perf time-utils: Fix 32-bit nsec parsing
authorIan Rogers <irogers@google.com>
Sat, 31 Aug 2024 07:04:11 +0000 (00:04 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 3 Sep 2024 14:21:55 +0000 (11:21 -0300)
The "time utils" test fails in 32-bit builds:
  ...
  parse_nsec_time("18446744073.709551615")
  Failed. ptime 4294967295709551615 expected 18446744073709551615
  ...

Switch strtoul to strtoull as an unsigned long in 32-bit build isn't
64-bits.

Fixes: c284d669a20d408b ("perf tools: Move parse_nsec_time to time-utils.c")
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: David Ahern <dsa@cumulusnetworks.com>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Junhao He <hejunhao3@huawei.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yang Jihong <yangjihong@bytedance.com>
Link: https://lore.kernel.org/r/20240831070415.506194-3-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/time-utils.c

index 302443921681632bfe54d57dd2386bfdfac0c084..1b91ccd4d52348550e8faa4b62f4c6a839030c91 100644 (file)
@@ -20,7 +20,7 @@ int parse_nsec_time(const char *str, u64 *ptime)
        u64 time_sec, time_nsec;
        char *end;
 
-       time_sec = strtoul(str, &end, 10);
+       time_sec = strtoull(str, &end, 10);
        if (*end != '.' && *end != '\0')
                return -1;
 
@@ -38,7 +38,7 @@ int parse_nsec_time(const char *str, u64 *ptime)
                for (i = strlen(nsec_buf); i < 9; i++)
                        nsec_buf[i] = '0';
 
-               time_nsec = strtoul(nsec_buf, &end, 10);
+               time_nsec = strtoull(nsec_buf, &end, 10);
                if (*end != '\0')
                        return -1;
        } else