linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: linux-trace-devel@vger.kernel.org,
	Tzvetomir Stoyanov <tz.stoyanov@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Claire Jensen <cjense@google.com>
Cc: Ian Rogers <irogers@google.com>
Subject: [PATCH] trace-cmd: Fix out of range comparison
Date: Wed,  4 Aug 2021 21:36:10 -0700	[thread overview]
Message-ID: <20210805043610.2116406-1-irogers@google.com> (raw)

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


                 reply	other threads:[~2021-08-05  4:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210805043610.2116406-1-irogers@google.com \
    --to=irogers@google.com \
    --cc=cjense@google.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tz.stoyanov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).