summaryrefslogtreecommitdiff
path: root/lib/reallocarray.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-04-24 10:45:45 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-04-24 10:47:40 -0700
commita7477abe2943c73bf23f39da2b706ea338d1c9b3 (patch)
treef72f501606ee663d311db129da10fcf1f1afce15 /lib/reallocarray.c
parente25cfaa3b59d3d7d8435e9e164a7f92e92c3f64d (diff)
downloadgnulib-a7477abe2943c73bf23f39da2b706ea338d1c9b3.tar.gz
reallocarray: check for ptrdiff_t overflow
* doc/glibc-functions/reallocarray.texi (reallocarray): Mention ptrdiff_t overflow. * lib/reallocarray.c (reallocarray): Reindent as per usual GNU. * lib/stdlib.in.h (reallocarray): Allow reallocarray to be replaced. * m4/reallocarray.m4 (gl_FUNC_REALLOCARRAY): Check for ptrdiff_t overflow. * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Set up REPLACE_REALLOCARRAY. * modules/reallocarray (Files): Add malloc.m4. (configure.ac): Also test REPLACE_REALLOCARRAY. * modules/reallocarray-tests (Depends-on): Add stdint. * modules/stdlib (stdlib.h): Substitute REPLACE_REALLOCARRAY. * tests/test-reallocarray.c: Include stdint.h. (main): Check for ptrdiff_t overflow.
Diffstat (limited to 'lib/reallocarray.c')
-rw-r--r--lib/reallocarray.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/reallocarray.c b/lib/reallocarray.c
index d10d7d5f57..03197c601b 100644
--- a/lib/reallocarray.c
+++ b/lib/reallocarray.c
@@ -27,12 +27,12 @@
void *
reallocarray (void *ptr, size_t nmemb, size_t size)
{
- if (xalloc_oversized (nmemb, size))
- {
- errno = ENOMEM;
- return NULL;
- }
-
- /* Rely on the semantics of GNU realloc. */
- return realloc (ptr, nmemb * size);
+ if (xalloc_oversized (nmemb, size))
+ {
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ /* Rely on the semantics of GNU realloc. */
+ return realloc (ptr, nmemb * size);
}