bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/6] regex: port to hosts where malloc (0) == NULL


From: Paul Eggert
Subject: [PATCH 3/6] regex: port to hosts where malloc (0) == NULL
Date: Sun, 30 Dec 2012 00:16:04 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

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            | 9 +++++++++
 lib/regex_internal.c | 2 +-
 lib/regex_internal.h | 6 ++++++
 m4/regex.m4          | 1 +
 modules/regex        | 1 +
 5 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index b3e202a..71ae04d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2012-12-29  Paul Eggert  <address@hidden>
 
+       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>.
diff --git a/lib/regex_internal.c b/lib/regex_internal.c
index 62b029d..cac0190 100644
--- a/lib/regex_internal.c
+++ b/lib/regex_internal.c
@@ -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;
 }
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 79c5f20..9c746f5 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -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
diff --git a/m4/regex.m4 b/m4/regex.m4
index 41be5e8..1622027 100644
--- a/m4/regex.m4
+++ b/m4/regex.m4
@@ -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>]])
diff --git a/modules/regex b/modules/regex
index cfc5d07..279f10a 100644
--- a/modules/regex
+++ b/modules/regex
@@ -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
 
-- 
1.7.11.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]