Re: New function xpalloc in module xalloc

2021-04-06 Thread Paul Eggert
On 4/6/21 12:23 PM, Marc Nieper-Wißkirchen wrote: Where is the flaw in my reasoning? Oh, you're right; any nonnegative signed integer value will fit into uintmax_t. (Perhaps this wasn't always true in older standards, but it's true of the recent C standard.) So that cast should work. Still,

Re: New function xpalloc in module xalloc

2021-04-06 Thread Marc Nieper-Wißkirchen
Am Di., 6. Apr. 2021 um 21:05 Uhr schrieb Paul Eggert : > On 4/5/21 11:48 PM, Marc Nieper-Wißkirchen wrote: > > SIZE_MAX < (uintmax_t) nbytes > > Eeuuw! That's a cure worse than the disease. Among other things, there > is no guarantee that PTRDIFF_MAX <= UINTMAX_MAX so in theory the > comparison c

Re: New function xpalloc in module xalloc

2021-04-06 Thread Paul Eggert
On 4/5/21 11:48 PM, Marc Nieper-Wißkirchen wrote: SIZE_MAX < (uintmax_t) nbytes Eeuuw! That's a cure worse than the disease. Among other things, there is no guarantee that PTRDIFF_MAX <= UINTMAX_MAX so in theory the comparison could go completely awry with a sufficiently-large NBYTES. "Don'

Re: New function xpalloc in module xalloc

2021-04-05 Thread Marc Nieper-Wißkirchen
Hi Paul, Am Di., 6. Apr. 2021 um 05:19 Uhr schrieb Paul Eggert : > On 4/3/21 11:17 PM, Marc Nieper-Wißkirchen wrote: > > Does the comparison make any sense, by the way? > > Yes, although it's needed only on unusual (and these days perhaps > theoretical?) platforms where SIZE_MAX < PTRDIFF_MAX. >

Re: New function xpalloc in module xalloc

2021-04-05 Thread Paul Eggert
On 4/3/21 11:17 PM, Marc Nieper-Wißkirchen wrote: Does the comparison make any sense, by the way? Yes, although it's needed only on unusual (and these days perhaps theoretical?) platforms where SIZE_MAX < PTRDIFF_MAX. I hadn't noticed the issue, as the projects I contribute to (coreutils, e

Re: New function xpalloc in module xalloc

2021-04-03 Thread Marc Nieper-Wißkirchen
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

Re: New function xpalloc in module xalloc

2021-04-03 Thread Jeffrey Walton
On Sun, Apr 4, 2021 at 2:17 AM Marc Nieper-Wißkirchen 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' {a

New function xpalloc in module xalloc

2021-04-03 Thread Marc Nieper-Wißkirchen
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, ite