bug-gnulib
[Top][All Lists]
Advanced

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

Re: New function xpalloc in module xalloc


From: Jeffrey Walton
Subject: Re: New function xpalloc in module xalloc
Date: Sun, 4 Apr 2021 02:23:57 -0400

On Sun, Apr 4, 2021 at 2:17 AM Marc Nieper-Wißkirchen
<marc.nieper+gnu@gmail.com> wrote:
>
> GCC prints the following warning when compiling the new code:
>
> lib/xmalloc.c: In function 'xpalloc':
> lib/xmalloc.c:132:64: warning: comparison of integer expressions of different 
> signedness: 'long unsigned int' and 'idx_t' {aka 'long int'} [-Wsign-compare]
>   132 |     = ((INT_MULTIPLY_WRAPV (n, item_size, &nbytes) || SIZE_MAX < 
> nbytes)
>
> If I understand the error message correctly, it is because 'nbytes' is a 
> signed type while SIZE_MAX is unsigned.
>
> Does the comparison make any sense, by the way?

Only for positive integers.

If idx_t is negative, like -1, then -1 will be promoted to an unsigned
type and then -1 > 0.

Jeff



reply via email to

[Prev in Thread] Current Thread [Next in Thread]