diff --git a/include/regex.h b/include/regex.h index 24eca2c297..76fa798861 100644 --- a/include/regex.h +++ b/include/regex.h @@ -36,8 +36,24 @@ extern void __re_set_registers extern int __regcomp (regex_t *__preg, const char *__pattern, int __cflags); libc_hidden_proto (__regcomp) + +#ifndef __ARG_NELTS +# ifdef __ARG_NELTS +/* Same as the corresponding cdefs.h macro. Defined for builds with + no cdefs.h. */ +# define __ARG_NELTS(arg) __ARG_NELTS (arg) +# elif (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \ + && !defined __STDC_NO_VLA__) +# define __ARG_NELTS(n) n +# else +# define __ARG_NELTS(n) +# endif +#endif + extern int __regexec (const regex_t *__preg, const char *__string, - size_t __nmatch, regmatch_t __pmatch[], int __eflags); + size_t __nmatch, + regmatch_t __pmatch[__ARG_NELTS (__nmatch)], + int __eflags); libc_hidden_proto (__regexec) extern size_t __regerror (int __errcode, const regex_t *__preg, diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index e490fc1aeb..64e46df190 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -632,4 +632,17 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf # define __attribute_returns_twice__ /* Ignore. */ #endif +#ifndef __ARG_NELTS +# ifdef __ARG_NELTS +/* Used to specify a variable bound in a declaration of a function + VLA-like parameter, as in 'int f (int n, int[__ARG_NELTS (n)]);' */ +# define __ARG_NELTS(arg) __ARG_NELTS (arg) +# elif (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \ + && !defined __STDC_NO_VLA__) +# define __ARG_NELTS(n) n +# else +# define __ARG_NELTS(n) +# endif +#endif + #endif /* sys/cdefs.h */ diff --git a/posix/regex.h b/posix/regex.h index 14fb1d8364..5b44f8e52b 100644 --- a/posix/regex.h +++ b/posix/regex.h @@ -654,9 +654,8 @@ extern int regcomp (regex_t *_Restrict_ __preg, extern int regexec (const regex_t *_Restrict_ __preg, const char *_Restrict_ __String, size_t __nmatch, - regmatch_t __pmatch[_Restrict_arr_], - int __eflags) - __attr_access ((__write_only__, 4, 3)); + regmatch_t __pmatch[_Restrict_arr_ __ARG_NELTS (__nmatch)], + int __eflags); extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg, char *_Restrict_ __errbuf, size_t __errbuf_size) diff --git a/posix/regexec.c b/posix/regexec.c index f7b4f9cfc3..bec2fdfe39 100644 --- a/posix/regexec.c +++ b/posix/regexec.c @@ -190,7 +190,7 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len); int regexec (const regex_t *__restrict preg, const char *__restrict string, - size_t nmatch, regmatch_t pmatch[], int eflags) + size_t nmatch, regmatch_t pmatch[__ARG_NELTS (nmatch)], int eflags) { reg_errcode_t err; Idx start, length;