summaryrefslogtreecommitdiff
path: root/lib/malloca.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-12-15 09:56:53 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2016-12-15 10:19:48 -0800
commitca495b0f87b2626156c8e51555fbd58c9129d3cc (patch)
treef81019f97270d20fd60265a36ff8be554a7d19e8 /lib/malloca.h
parentcb4e027f61170badd1d856a60a1c02a01edf3bda (diff)
downloadgnulib-ca495b0f87b2626156c8e51555fbd58c9129d3cc.tar.gz
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.
Diffstat (limited to 'lib/malloca.h')
-rw-r--r--lib/malloca.h13
1 files changed, 4 insertions, 9 deletions
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 <alloca.h>
#include <stddef.h>
#include <stdlib.h>
+#include <stdint.h>
+
+#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