SIZE_MAX could be defined as -1 promoted to an unsigned type, meaning that the unsigned comparison would always yield false. Or am I missing something?
In any case, if the promotion is what is intended, 'nbytes' should be probably replaced with '(size_t) nbytes' to silence the warning and to make it explicit. Am So., 4. Apr. 2021 um 08:24 Uhr schrieb Jeffrey Walton <noloa...@gmail.com >: > On Sun, Apr 4, 2021 at 2:17 AM Marc Nieper-Wißkirchen > <marc.nieper+...@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 >