summaryrefslogtreecommitdiff
path: root/lib/reallocarray.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-04-25 23:11:15 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-04-25 23:12:25 -0700
commit354b9691accd00a531358b652689ce7f580fbe54 (patch)
treed10f9e2bedd2150a7138d9af901e9edf32aac0d6 /lib/reallocarray.c
parent974ddbe54c37dd1f8f0f0f11f6f967d6fecd864d (diff)
downloadgnulib-354b9691accd00a531358b652689ce7f580fbe54.tar.gz
reallocarray: a bit more tuning
* lib/reallocarray.c: Include intprops.h. (reallocarray): Use INT_MULTIPLY_WRAPV instead of xalloc_oversized, as it now suffices and is likely a bit more efficient (five fewer machine insns on Ubuntu 20.10 x86-64). * modules/reallocarray (Depends-on): Depend on intprops, not xalloc-oversized. Use conditional dependencies to avoid building realloc-gnu when not needed.
Diffstat (limited to 'lib/reallocarray.c')
-rw-r--r--lib/reallocarray.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/reallocarray.c b/lib/reallocarray.c
index 03197c601b..d5cfa05d57 100644
--- a/lib/reallocarray.c
+++ b/lib/reallocarray.c
@@ -22,17 +22,18 @@
#include <stdlib.h>
#include <errno.h>
-#include "xalloc-oversized.h"
+#include "intprops.h"
void *
reallocarray (void *ptr, size_t nmemb, size_t size)
{
- if (xalloc_oversized (nmemb, size))
+ size_t nbytes;
+ if (INT_MULTIPLY_WRAPV (nmemb, size, &nbytes))
{
errno = ENOMEM;
return NULL;
}
/* Rely on the semantics of GNU realloc. */
- return realloc (ptr, nmemb * size);
+ return realloc (ptr, nbytes);
}