Currently there is no wrapper for this function. As long as implementations just check for overflow and call realloc we are OK since we will intercept that. It's not safe to assume that and implementations could directly call their internal functions to handle the call. This was mentioned in https://bugs.kde.org/show_bug.cgi?id=407589 but I only fixed the aligned_alloc part.
Also adding a wrapper will slightly improve error messages. The FreeBSD implementation is void * reallocarray(void *optr, size_t nmemb, size_t size) { if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && nmemb > 0 && SIZE_MAX / nmemb < size) { errno = ENOMEM; return (NULL); } return (realloc(optr, size * nmemb)); } Illumos uses the same source (from OpenBSD) musl and GNU libc do the same thing but without the square root of MAX_SIZE checks to avoid the division.
Created attachment 162942 [details] initial patch Linux expected not yet generated
commit 993cdf80a15ecf2cdaaa10a120cb29949f22605f (HEAD -> master, origin/master, origin/HEAD, bug475498) Author: Paul Floyd <pjfloyd@wanadoo.fr> Date: Thu Nov 9 07:58:02 2023 +0100 Bug 475498 - Add reallocarray wrapper