This is for Gawk, which does not use malloc-gnu.
* lib/regex.c (_GL_USE_STDLIB_ALLOC) [!_LIBC]:
Define, since this module is now safe for AIX-like malloc.
* lib/regex_internal.h (re_malloc) [!_LIBC && !HAVE_MALLOC_0_NONNULL]:
Don’t pass 0 to malloc.
---
 ChangeLog            | 7 +++++++
 lib/regex.c          | 1 +
 lib/regex_internal.h | 6 +++++-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 95d69e6611..e50481b985 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2026-04-27  Paul Eggert  <[email protected]>
 
+       regex: port to non-GNU malloc
+       This is for Gawk, which does not use malloc-gnu.
+       * lib/regex.c (_GL_USE_STDLIB_ALLOC) [!_LIBC]:
+       Define, since this module is now safe for AIX-like malloc.
+       * lib/regex_internal.h (re_malloc) [!_LIBC && !HAVE_MALLOC_0_NONNULL]:
+       Don’t pass 0 to malloc.
+
        regex: SSIZE_MAX porting
        * lib/regex_internal.h (IDX_MAX) [_REGEX_LARGE_OFFSETS]:
        Port to non-POSIX platforms where limits.h does not define SSIZE_MAX.
diff --git a/lib/regex.c b/lib/regex.c
index f9f333d237..d0c7af9018 100644
--- a/lib/regex.c
+++ b/lib/regex.c
@@ -20,6 +20,7 @@
 #define __STDC_WANT_IEC_60559_BFP_EXT__
 
 #ifndef _LIBC
+# define _GL_USE_STDLIB_ALLOC 1
 # include <libc-config.h>
 
 # if __GNUC_PREREQ (4, 6)
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 6e526a6f38..c4e05ec72d 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -448,7 +448,11 @@ typedef struct re_dfa_t re_dfa_t;
 # define MIN(a,b) ((a) < (b) ? (a) : (b))
 #endif
 
-#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
+#if defined _LIBC || HAVE_MALLOC_0_NONNULL
+# define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
+#else
+# define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t) + !(n)))
+#endif
 #define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
 #define re_free(p) free (p)
 
-- 
2.53.0


Reply via email to