]> Savannah Git Hosting - gnulib.git/commitdiff
malloca: do not exceed PTRDIFF_MAX
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 15 Dec 2016 17:56:53 +0000 (09:56 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 15 Dec 2016 18:19:48 +0000 (10:19 -0800)
* 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.

ChangeLog
lib/malloca.h
modules/malloca
modules/relocatable-prog-wrapper

index 612d66ca731b8467229f53443d4180b8a2d2e9a3..07c4d6539662440898013cc80216bc0c8daa3589 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 46f27f033058bca0cb4bc54b6b94109fc3c77ac5..c00dbed93cef8c154d8ba6c7feda66c3ca5237a5 100644 (file)
@@ -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
index ca0be8941d5a553a61f77e0f05aa1c7e2d61f45f..9d4b40b6a86b8fb1dbf643f0bc31a428cfbbbf2f 100644 (file)
@@ -12,6 +12,7 @@ m4/longlong.m4
 Depends-on:
 alloca-opt
 stdint
+xalloc-oversized
 verify
 
 configure.ac:
index 50444b1a77eb74dc94b654143e63cb1538aaeb79..db451ef333fc68ff7a29e8b6778171bcfcfdd9a0 100644 (file)
@@ -47,6 +47,7 @@ unistd
 environ
 string
 verify
+xalloc-oversized
 
 configure.ac:
 gl_FUNC_READLINK_SEPARATE