summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2012-12-29 22:56:31 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2012-12-30 00:13:15 -0800
commitbbf0d723ed2335add96bcc0f842885d8a5d8b6da (patch)
tree321231ad125a0b3cae1ca1832ab8347db2b3b7e7 /lib
parent585a8dcf51a46cd9965c6881cfff6eddbae06d48 (diff)
downloadgnulib-bbf0d723ed2335add96bcc0f842885d8a5d8b6da.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/regex_internal.c2
-rw-r--r--lib/regex_internal.h6
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/regex_internal.c b/lib/regex_internal.c
index 62b029dbfa..cac0190994 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 79c5f20f3c..9c746f5e9f 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