From: Paul Eggert Date: Mon, 27 Apr 2026 21:55:39 +0000 (-0700) Subject: regex: port to non-GNU malloc X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2c97c592b2536de2db06231eccb3e9f7de5328d;p=thirdparty%2Fgnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 95d69e6611..e50481b985 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2026-04-27 Paul Eggert + 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 # 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)