[PATCH 2/2] malloc: make malloc fail with requests larger than PTRDIFF_MAX

Paul Eggert eggert@cs.ucla.edu
Sun Dec 23 20:28:00 GMT 2018


Joseph Myers wrote:
> We can assume that
> PTRDIFF_MAX == SIZE_MAX / 2 (and that ptrdiff_t, size_t and pointers have
> the same power-of-2 width, which is at least 32).

OK, then we needn't bother with the static assertion. Is there a good place to 
document assumptions like this one, in the glibc manual I suppose?

> Using verify.h in any glibc code not coming from gnulib would be odd; just
> use _Static_assert.

Although the point is now moot for this patch, I prefer the readability of 
'verify'. Compare this:

verify (PTRDIFF_MAX <= SIZE_MAX / 2);

to this:

_Static_assert (PTRDIFF_MAX <= SIZE_MAX / 2,
                 "PTRDIFF_MAX is not more than half of SIZE_MAX");

With just one static assertion it's no big deal, but Gnulib has files with 
dozens and the readability savings add up.



More information about the Libc-alpha mailing list