linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Chris Li <sparse@chrisli.org>,
	Ramsay Jones <ramsay@ramsayjones.plus.com>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v2 1/3] memcpy()'s byte count is unsigned
Date: Sat,  3 Jun 2017 09:47:25 +0200	[thread overview]
Message-ID: <20170603074727.66945-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170603074727.66945-1-luc.vanoostenryck@gmail.com>

The checker part of sparse does some checking on memcpy(),
memset(), copy_{from,to}_user() byte count and warn if the
value is known to be too large. The comparison is done with
signed numbers and it also warns if the value is negative.

However these functions take an unsigned byte count (size_t)
and so the value can't really be negative.

Additionaly, the number of bits used by sparse internally may not
be the same as the one used for the target's size_t. So sparse's
check against negative value may not be the same as checking if
the target's value would be so-large-than-the-upper-bit-is-set.

Change this by removing the test for negative values and simply
do an unsigned compare.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 sparse.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sparse.c b/sparse.c
index 02ab97743..1cb90e20d 100644
--- a/sparse.c
+++ b/sparse.c
@@ -152,9 +152,9 @@ static void check_byte_count(struct instruction *insn, pseudo_t count)
 	if (!count)
 		return;
 	if (count->type == PSEUDO_VAL) {
-		long long val = count->value;
-		if (val <= 0 || val > 100000)
-			warning(insn->pos, "%s with byte count of %lld",
+		unsigned long long val = count->value;
+		if (val > 100000ULL)
+			warning(insn->pos, "%s with byte count of %llu",
 				show_ident(insn->func->sym->ident), val);
 		return;
 	}
-- 
2.13.0


  reply	other threads:[~2017-06-03  7:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-03  7:47 [PATCH 0/3] -Wmemcpy-max-count & friends Luc Van Oostenryck
2017-06-03  7:47 ` Luc Van Oostenryck [this message]
2017-06-05 20:52   ` [PATCH v2 1/3] memcpy()'s byte count is unsigned Christopher Li
2017-06-05 22:16     ` Luc Van Oostenryck
2017-06-06  1:26       ` Christopher Li
2017-06-05 22:20     ` [PATCH v2 0/3] -Wmemcpy-max-count & friends Luc Van Oostenryck
2017-06-03  7:47 ` [PATCH v2 2/3] add support for -Wmemcpy-max-count Luc Van Oostenryck
2017-06-03  7:47 ` [PATCH v2 3/3] add support for -fmemcpy-max-count Luc Van Oostenryck
2017-06-03 13:23 ` [PATCH 0/3] -Wmemcpy-max-count & friends Ramsay Jones
2017-06-06  1:39 ` Christopher Li

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=20170603074727.66945-2-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=ramsay@ramsayjones.plus.com \
    --cc=sparse@chrisli.org \
    /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).