From: Paul Eggert Date: Thu, 15 Dec 2016 17:56:53 +0000 (-0800) Subject: malloca: do not exceed PTRDIFF_MAX X-Git-Tag: v1.0~6496 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=ca495b0f87b2626156c8e51555fbd58c9129d3cc;p=gnulib.git malloca: do not exceed PTRDIFF_MAX * lib/malloca.h: Include xalloc-oversized. (nmalloca): Use xalloc_oversized instead of rolling our own. * modules/malloca (Depends-on): * modules/relocatable-prog-wrapper (Depends-on): Add xalloc-oversized. --- diff --git a/ChangeLog b/ChangeLog index 612d66ca73..07c4d65396 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2016-12-15 Paul Eggert + malloca: do not exceed PTRDIFF_MAX + * lib/malloca.h: Include xalloc-oversized. + (nmalloca): Use xalloc_oversized instead of rolling our own. + * modules/malloca (Depends-on): + * modules/relocatable-prog-wrapper (Depends-on): + Add xalloc-oversized. + quotearg: pacify GCC better * modules/quotearg (Depends-on): Add minmax, stdint. * lib/quotearg.c: Include minmax.h, stdint.h. diff --git a/lib/malloca.h b/lib/malloca.h index 46f27f0330..c00dbed93c 100644 --- a/lib/malloca.h +++ b/lib/malloca.h @@ -21,6 +21,9 @@ #include #include #include +#include + +#include "xalloc-oversized.h" #ifdef __cplusplus @@ -73,15 +76,7 @@ extern void freea (void *p); It allocates an array of N objects, each with S bytes of memory, on the stack. S must be positive and N must be nonnegative. The array must be freed using freea() before the function returns. */ -#if 1 -/* Cf. the definition of xalloc_oversized. */ -# define nmalloca(n, s) \ - ((n) > (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) \ - ? NULL \ - : malloca ((n) * (s))) -#else -extern void * nmalloca (size_t n, size_t s); -#endif +#define nmalloca(n, s) (xalloc_oversized (n, s) ? NULL : malloca ((n) * (s))) #ifdef __cplusplus diff --git a/modules/malloca b/modules/malloca index ca0be8941d..9d4b40b6a8 100644 --- a/modules/malloca +++ b/modules/malloca @@ -12,6 +12,7 @@ m4/longlong.m4 Depends-on: alloca-opt stdint +xalloc-oversized verify configure.ac: diff --git a/modules/relocatable-prog-wrapper b/modules/relocatable-prog-wrapper index 50444b1a77..db451ef333 100644 --- a/modules/relocatable-prog-wrapper +++ b/modules/relocatable-prog-wrapper @@ -47,6 +47,7 @@ unistd environ string verify +xalloc-oversized configure.ac: gl_FUNC_READLINK_SEPARATE