This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 2/2] malloc: make malloc fail with requests larger than PTRDIFF_MAX
On Fri, 21 Dec 2018, Paul Eggert wrote:
> The patch assumes that PTRDIFF_MAX is well under SIZE_MAX. A while ago Joseph
> wrote that m32c sometimes has ptrdiff_t wider than size_t
> <https://gcc.gnu.org/ml/gcc-patches/2011-07/msg00483.html> and if someone ever
> does a glibc port to such a platform this issue will come up in unlikely
> cases. Perhaps add something like the following to malloc/malloc.c, to make
> sure the problem is harder to ignore on such platforms?
Such platforms are well outside the scope of glibc. 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).
> #include <verify.h>
> verify (PTRDIFF_MAX <= SIZE_MAX / 2);
Using verify.h in any glibc code not coming from gnulib would be odd; just
use _Static_assert.
--
Joseph S. Myers
joseph@codesourcery.com