diff mbox series

trace-cmd: Fix out of range comparison

Message ID 20210805043610.2116406-1-irogers@google.com (mailing list archive)
State Accepted
Commit 6a0fca63e3de79bcafd1043535495b263be4ee7e
Headers show
Series trace-cmd: Fix out of range comparison | expand

Commit Message

Ian Rogers Aug. 5, 2021, 4:36 a.m. UTC
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 mbox series

Patch

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)