* [PATCH] trace-cmd: Fix out of range comparison
@ 2021-08-05 4:36 Ian Rogers
0 siblings, 0 replies; only message in thread
From: Ian Rogers @ 2021-08-05 4:36 UTC (permalink / raw)
To: linux-trace-devel, Tzvetomir Stoyanov, Steven Rostedt,
Claire Jensen
Cc: Ian Rogers
Comparing an unsigned int with a uint64_t causes zero extension of the
unsigned int. This doesn't allow the unsigned int to ever equal LONG_MIN
or LONG_MAX, i.e the branch is always false.
This issue was caught by clang:
tracecmd/trace-vm.c:340:37: error: result of comparison of constant 9223372036854775807 with expression of type 'unsigned int' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
if ((cid_id == LONG_MIN || cid_id == LONG_MAX) && errno == ERANGE)
~~~~~~ ^ ~~~~~~~~
tracecmd/trace-vm.c:340:15: error: result of comparison of constant -9223372036854775808 with expression of type 'unsigned int' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
if ((cid_id == LONG_MIN || cid_id == LONG_MAX) && errno == ERANGE)
Signed-off-by: Ian Rogers <irogers@google.com>
---
tracecmd/trace-vm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tracecmd/trace-vm.c b/tracecmd/trace-vm.c
index d204411..02979ba 100644
--- a/tracecmd/trace-vm.c
+++ b/tracecmd/trace-vm.c
@@ -337,7 +337,7 @@ static void read_guest_cid(char *name)
if (!cid)
continue;
cid_id = strtol(cid + strlen(VM_CID_ID), NULL, 10);
- if ((cid_id == LONG_MIN || cid_id == LONG_MAX) && errno == ERANGE)
+ if ((cid_id == INT_MIN || cid_id == INT_MAX) && errno == ERANGE)
continue;
guest = add_guest(cid_id, name);
if (guest)
--
2.32.0.605.g8dce9f2422-goog
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-05 4:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-05 4:36 [PATCH] trace-cmd: Fix out of range comparison Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).