]> Savannah Git Hosting - gnulib.git/commitdiff
regex: Fix undefined behaviour.
authorBruno Haible <bruno@clisp.org>
Mon, 14 Apr 2025 14:00:13 +0000 (16:00 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 14 Apr 2025 14:16:19 +0000 (16:16 +0200)
* lib/regex.h (_REGEX_NELTS): Define to empty; don't use ISO C99
variable-length arrays.

ChangeLog
lib/regex.h

index 4aa2a83c080052997e1a4216fdec196dbf3551eb..0b1d316a2436395426528166f87d484e63eabc8a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-04-14  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        select tests: Work around a Cygwin bug.
index ff7e43b534a544e65d4e49ae2fc511ea5e4ddafb..0eb72ce908b5c0e8edc21cb34a5f2ecbdb915961 100644 (file)
@@ -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)