Technically realloc should handle this:

" However, unlike that *realloc*() call, *reallocarray*() fails safely in

       the case where the multiplication would overflow.  If such an over‐
       flow occurs, *reallocarray*() returns NULL, sets *errno
<http://man7.org/linux/man-pages/man3/errno.3.html>* to *ENOMEM*, and
       leaves the original block of memory unchanged."


On Sun, May 3, 2020 at 6:27 PM Commit Bot <b...@cloudius-systems.com> wrote:

> From: Waldemar Kozaczuk <jwkozac...@gmail.com>
> Committer: Waldemar Kozaczuk <jwkozac...@gmail.com>
> Branch: master
>
> libc: add reallocarray
>
> Some apps like xclock from Fedora need reallocarray() which
> this patch adds as simple delegation to realloc.
>
> Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
>
> ---
> diff --git a/core/mempool.cc b/core/mempool.cc
> --- a/core/mempool.cc
> +++ b/core/mempool.cc
> @@ -2014,6 +2014,11 @@ void* realloc(void* obj, size_t size)
>      return buf;
>  }
>
> +extern "C" void *reallocarray(void *ptr, size_t nmemb, size_t size)
> +{
> +    return realloc(ptr, nmemb * size);
> +}
> +
>  size_t malloc_usable_size(void* obj)
>  {
>      if ( obj == nullptr ) {
>

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/CAL9cFfMmmVrmWnfSb-PbW1UmOT%2B5gWm%3D6QDhrCUk7U%2BdW1q7Bw%40mail.gmail.com.

Reply via email to