# HG changeset patch # User Paul Eggert # Date 1356850591 28800 # Node ID e101c2620c25443e6400189578e6ce48b751ea30 # Parent de636633c6cd0943de93fc09477892f343521655 regex: port to hosts where malloc (0) == NULL Reported by Aharon Robbins in . * 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. diff -r de636633c6cd -r e101c2620c25 ChangeLog --- a/ChangeLog Sat Dec 29 22:52:17 2012 -0800 +++ b/ChangeLog Sat Dec 29 22:56:31 2012 -0800 @@ -1,5 +1,14 @@ 2012-12-29 Paul Eggert + regex: port to hosts where malloc (0) == NULL + Reported by Aharon Robbins in + . + * 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 . diff -r de636633c6cd -r e101c2620c25 lib/regex_internal.c --- a/lib/regex_internal.c Sat Dec 29 22:52:17 2012 -0800 +++ b/lib/regex_internal.c Sat Dec 29 22:56:31 2012 -0800 @@ -974,7 +974,7 @@ 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 -r de636633c6cd -r e101c2620c25 lib/regex_internal.h --- a/lib/regex_internal.h Sat Dec 29 22:52:17 2012 -0800 +++ b/lib/regex_internal.h Sat Dec 29 22:56:31 2012 -0800 @@ -464,6 +464,12 @@ # 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 -r de636633c6cd -r e101c2620c25 m4/regex.m4 --- a/m4/regex.m4 Sat Dec 29 22:52:17 2012 -0800 +++ b/m4/regex.m4 Sat Dec 29 22:56:31 2012 -0800 @@ -220,6 +220,7 @@ 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 ]]) diff -r de636633c6cd -r e101c2620c25 modules/regex --- a/modules/regex Sat Dec 29 22:52:17 2012 -0800 +++ b/modules/regex Sat Dec 29 22:56:31 2012 -0800 @@ -8,6 +8,7 @@ lib/regex_internal.h lib/regexec.c lib/regcomp.c +m4/eealloc.m4 m4/regex.m4 m4/mbstate_t.m4