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

Florian Weimer fw@deneb.enyo.de
Fri Dec 21 22:37:00 GMT 2018


* Adhemerval Zanella:

> +* Memory allocation functions malloc, calloc, realloc, reallocarray, valloc,
> +  pvalloc, memalign, and posix_memalign fail now fail with requests larger
> +  than PTRDIFF_MAX.  This is to avoid potential undefined behavior with
> +  pointer subtraction within the allocated object, where results might
> +  overflow the ptrdiff_t type.

“fail now fail”.  “with requests larger than PTRDIFF_MAX” is
under-specified for calloc and reallocarray.  The intent probably is
that the total object size counts.

I have not reviewed the actual patch.



More information about the Libc-alpha mailing list