]> Savannah Git Hosting - gnulib.git/commitdiff
regex: port to hosts where malloc (0) == NULL
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 30 Dec 2012 06:56:31 +0000 (22:56 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 30 Dec 2012 08:13:15 +0000 (00:13 -0800)
Reported by Aharon Robbins in
<http://sourceware.org/ml/libc-alpha/2012-12/msg00456.html>.
* lib/regex_internal.c (re_node_set_alloc):
Don't assume that malloc (0) yields nonnull.
* lib/regex_internal.h (MALLOC_0_IS_NONNULL): New macro.
* m4/regex.m4 (gl_PREREQ_REGEX): Require gl_EEMALLOC.
* modules/regex (Files): Add m4/eealloc.m4.

ChangeLog
lib/regex_internal.c
lib/regex_internal.h
m4/regex.m4
modules/regex

index b3e202a2adb0293fb0f6a138faebe5c6145f99ed..71ae04df798bd72ceb70e97c6b4832cb0e472f57 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2012-12-29  Paul Eggert  <eggert@cs.ucla.edu>
 
+       regex: port to hosts where malloc (0) == NULL
+       Reported by Aharon Robbins in
+       <http://sourceware.org/ml/libc-alpha/2012-12/msg00456.html>.
+       * lib/regex_internal.c (re_node_set_alloc):
+       Don't assume that malloc (0) yields nonnull.
+       * lib/regex_internal.h (MALLOC_0_IS_NONNULL): New macro.
+       * m4/regex.m4 (gl_PREREQ_REGEX): Require gl_EEMALLOC.
+       * modules/regex (Files): Add m4/eealloc.m4.
+
        regex: port to C89
        Reported by Aharon Robbins in
        <http://sourceware.org/ml/libc-alpha/2012-12/msg00456.html>.
index 62b029dbfa6c711f4050c526ac4e01e9bea7f1e3..cac0190994a9ab43c92296bcdc40b6844d631a45 100644 (file)
@@ -974,7 +974,7 @@ re_node_set_alloc (re_node_set *set, Idx size)
   set->alloc = size;
   set->nelem = 0;
   set->elems = re_malloc (Idx, size);
-  if (BE (set->elems == NULL, 0))
+  if (BE (set->elems == NULL, 0) && (MALLOC_0_IS_NONNULL || size != 0))
     return REG_ESPACE;
   return REG_NOERROR;
 }
index 79c5f20f3c50e8b2f58b0ec7924306f61515c996..9c746f5e9f8f23e5f36d02fbc4f89ff0bec3423f 100644 (file)
@@ -464,6 +464,12 @@ static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
 # endif
 #endif
 
+#ifdef _LIBC
+# define MALLOC_0_IS_NONNULL 1
+#elif !defined MALLOC_0_IS_NONNULL
+# define MALLOC_0_IS_NONNULL 0
+#endif
+
 #ifndef MAX
 # define MAX(a,b) ((a) < (b) ? (b) : (a))
 #endif
index 41be5e8d3c128a3579891b21bc14a81fe2137937..162202768151ea79e1daa1c06fc0f1224fcfbd04 100644 (file)
@@ -220,6 +220,7 @@ AC_DEFUN([gl_PREREQ_REGEX],
   AC_REQUIRE([AC_C_INLINE])
   AC_REQUIRE([AC_C_RESTRICT])
   AC_REQUIRE([AC_TYPE_MBSTATE_T])
+  AC_REQUIRE([gl_EEMALLOC])
   AC_CHECK_HEADERS([libintl.h])
   AC_CHECK_FUNCS_ONCE([isblank iswctype wcscoll])
   AC_CHECK_DECLS([isblank], [], [], [[#include <ctype.h>]])
index cfc5d0707899131ee5c6f329f65fa14f2c2316cc..279f10a10b833f780337d6a518c63d12f2e84dab 100644 (file)
@@ -8,6 +8,7 @@ lib/regex_internal.c
 lib/regex_internal.h
 lib/regexec.c
 lib/regcomp.c
+m4/eealloc.m4
 m4/regex.m4
 m4/mbstate_t.m4