changeset 38242:ab7a57bd5e3b

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.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 15 Dec 2016 09:56:53 -0800
parents 909a440ad711
children f9bc62578d4a
files ChangeLog lib/malloca.h modules/malloca modules/relocatable-prog-wrapper
diffstat 4 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Dec 15 09:53:45 2016 -0800
+++ b/ChangeLog	Thu Dec 15 09:56:53 2016 -0800
@@ -1,5 +1,12 @@
 2016-12-15  Paul Eggert  <eggert@cs.ucla.edu>
 
+	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.
--- a/lib/malloca.h	Thu Dec 15 09:53:45 2016 -0800
+++ b/lib/malloca.h	Thu Dec 15 09:56:53 2016 -0800
@@ -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 @@
    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
--- a/modules/malloca	Thu Dec 15 09:53:45 2016 -0800
+++ b/modules/malloca	Thu Dec 15 09:56:53 2016 -0800
@@ -12,6 +12,7 @@
 Depends-on:
 alloca-opt
 stdint
+xalloc-oversized
 verify
 
 configure.ac:
--- a/modules/relocatable-prog-wrapper	Thu Dec 15 09:53:45 2016 -0800
+++ b/modules/relocatable-prog-wrapper	Thu Dec 15 09:56:53 2016 -0800
@@ -47,6 +47,7 @@
 environ
 string
 verify
+xalloc-oversized
 
 configure.ac:
 gl_FUNC_READLINK_SEPARATE