From 0b5ca7c3e551e5502f3be3b06453324fe8604e82 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 21 Sep 2021 07:47:45 -0700 Subject: regex: copy back from Gnulib Copy regex-related files back from Gnulib, to fix a problem with static checking of regex calls noted by Martin Sebor. This merges the following changes: * New macro __attribute_nonnull__ in misc/sys/cdefs.h, for use later when copying other files back from Gnulib. * Use __GNULIB_CDEFS instead of __GLIBC__ when deciding whether to include bits/wordsize.h etc. * Avoid duplicate entries in epsilon closure table. * New regex.h macro _REGEX_NELTS to let regexec say that its pmatch arg should contain nmatch elts. Use that for regexec, instead of __attr_access (which is incorrect). * New regex.h macro _Attr_access_ which is like __attr_access except portable to non-glibc platforms. * Add some DEBUG_ASSERTs to pacify gcc -fanalyzer and to catch recently-fixed performance bugs if they recur. * Add Gnulib-specific stuff to port the dynarray- and lock-using parts of regex code to non-glibc platforms. * Fix glibc bug 11053. * Avoid some undefined behavior when popping an empty fail stack. --- posix/regex_internal.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'posix/regex_internal.c') diff --git a/posix/regex_internal.c b/posix/regex_internal.c index 9dd387e..aefcfa2 100644 --- a/posix/regex_internal.c +++ b/posix/regex_internal.c @@ -1211,6 +1211,10 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src) if (__glibc_unlikely (dest->nelem == 0)) { + /* Although we already guaranteed above that dest->alloc != 0 and + therefore dest->elems != NULL, add a debug assertion to pacify + GCC 11.2.1's -fanalyzer. */ + DEBUG_ASSERT (dest->elems); dest->nelem = src->nelem; memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx)); return REG_NOERROR; @@ -1286,7 +1290,10 @@ re_node_set_insert (re_node_set *set, Idx elem) if (__glibc_unlikely (set->nelem) == 0) { - /* We already guaranteed above that set->alloc != 0. */ + /* Although we already guaranteed above that set->alloc != 0 and + therefore set->elems != NULL, add a debug assertion to pacify + GCC 11.2 -fanalyzer. */ + DEBUG_ASSERT (set->elems); set->elems[0] = elem; ++set->nelem; return true; @@ -1314,6 +1321,7 @@ re_node_set_insert (re_node_set *set, Idx elem) { for (idx = set->nelem; set->elems[idx - 1] > elem; idx--) set->elems[idx] = set->elems[idx - 1]; + DEBUG_ASSERT (set->elems[idx - 1] < elem); } /* Insert the new element. */ -- cgit v1.1