Re: [PATCH 0/9] commit-reach: -Wsign-compare follow-ups

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Junio C Hamano <gitster@xxxxxxxxx> writes:

> Error: shallow.c:537:32: comparison of integer expressions of different signedness:
> 'unsigned int' and 'int' [-Werror=sign-compare]
>
>     537 |  if (!info->pool_count || size > info->end - info->free) {
>
> I didn't dig deeper than this.

What we want to express seems to be:

    If the region between "end" and "free" is smaller than the
    required "size" then we are in trouble.

which can be said more naturally with

    If the region of size "size" starting at "free" pointer overruns the
    "end" pointer, we are in trouble.

So perhaps something like this would help?  We are no longer making
a comparison between two integers with this rewrite.

 shallow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git c/shallow.c w/shallow.c
index b8fcfbef0f..b54244ffa9 100644
--- c/shallow.c
+++ w/shallow.c
@@ -534,7 +534,7 @@ static uint32_t *paint_alloc(struct paint_info *info)
 	unsigned nr = DIV_ROUND_UP(info->nr_bits, 32);
 	unsigned size = nr * sizeof(uint32_t);
 	void *p;
-	if (!info->pool_count || size > info->end - info->free) {
+	if (!info->pool_count || info->end < info->free + size) {
 		if (size > POOL_SIZE)
 			BUG("pool size too small for %d in paint_alloc()",
 			    size);




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux