From 500d839fdfbc507e53ca1d3cf502e6b190b0fcf5 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 14 Apr 2025 16:00:13 +0200 Subject: [PATCH] regex: Fix undefined behaviour. * lib/regex.h (_REGEX_NELTS): Define to empty; don't use ISO C99 variable-length arrays. --- ChangeLog | 6 ++++++ lib/regex.h | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4aa2a83c08..0b1d316a24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-04-14 Bruno Haible + + regex: Fix undefined behaviour. + * lib/regex.h (_REGEX_NELTS): Define to empty; don't use ISO C99 + variable-length arrays. + 2025-04-14 Bruno Haible select tests: Work around a Cygwin bug. diff --git a/lib/regex.h b/lib/regex.h index ff7e43b534..0eb72ce908 100644 --- a/lib/regex.h +++ b/lib/regex.h @@ -523,8 +523,12 @@ typedef struct /* Declarations for routines. */ #ifndef _REGEX_NELTS -# if (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \ - && !defined __STDC_NO_VLA__) +/* The macro _REGEX_NELTS denotes the number of elements in a variable-length + array passed to a function. + It was meant to make use of ISO C99 variable-length arrays, but this does + not work: ISO C23 § 6.7.6.2.(5) requires the number of elements to be > 0, + but the NMATCH argument to regexec() is allowed to be 0. */ +# if 0 # define _REGEX_NELTS(n) n # else # define _REGEX_NELTS(n) -- 2.39.5