summaryrefslogtreecommitdiff
path: root/lib/cdefs.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-08-26 10:08:00 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-08-26 15:44:40 -0700
commit56b322516f8471584c8c67d2f749ae635560eeca (patch)
treebf63b196435c09a51e448097fcb41be365f71d2f /lib/cdefs.h
parent8fb3a827a2635915a9baa3926e6be6fad7b9ab2d (diff)
downloadgnulib-56b322516f8471584c8c67d2f749ae635560eeca.tar.gz
regex: use C99-style array arg syntax
This should help with some static checking. Derived from a suggestion by Martin Sebor in: https://sourceware.org/pipermail/libc-alpha/2021-August/130336.html This also ports recent and relevant Glibc changes to Gnulib and prepares to copy back. * lib/cdefs.h (__ARG_NELTS): New macro. * lib/regex.c: Ignore -Wvla for the whole file. * lib/regex.h (_ARG_NELTS_, _Attr_access_): New macros. Ignore -Wvla when declaring regexec. * lib/regex.h (re_compile_pattern, re_search, re_search_2) (re_match, re_match_2, regcomp, regerror): Use _Attr_access_ where that could help static checking. * lib/regexec.c (regexec, __compat_regexec, re_copy_regs) (re_search_internal, proceed_next_node, push_fail_stack) (pop_fail_stack, set_regs, update_regs): Use __ARG_NELTS for each array parameter whose size is another arg, but which might be null.
Diffstat (limited to 'lib/cdefs.h')
-rw-r--r--lib/cdefs.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/cdefs.h b/lib/cdefs.h
index 4dac9d264d..13c5542bfd 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -634,4 +634,13 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf
# define __attribute_returns_twice__ /* Ignore. */
#endif
+/* Specify the number of elements of a function's array parameter,
+ as in 'int f (int n, int a[__ARG_NELTS (n)]);'. */
+#if (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \
+ && !defined __STDC_NO_VLA__)
+# define __ARG_NELTS(n) n
+#else
+# define __ARG_NELTS(n)
+#endif
+
#endif /* sys/cdefs.h */