[PATCH 2/2] regex: pacify 16.1.1 -Wanalyzer-out-of-bounds

Paul Eggert <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <[email protected]>
* lib/regex_internal.c (re_node_set_insert): Add a DEBUG_ASSERT.
Needed for gcc 16.1.1 20260515 (Red Hat 16.1.1-2) on x86-64 when
_REGEX_AVOID_UCHAR_H is defined.
---
 ChangeLog            | 5 +++++
 lib/regex_internal.c | 8 +++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 169ee053dd..556c9bf5b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2026-05-24  Paul Eggert  <[email protected]>
 
+	regex: pacify 16.1.1 -Wanalyzer-out-of-bounds
+	* lib/regex_internal.c (re_node_set_insert): Add a DEBUG_ASSERT.
+	Needed for gcc 16.1.1 20260515 (Red Hat 16.1.1-2) on x86-64 when
+	_REGEX_AVOID_UCHAR_H is defined.
+
 	regex: new _REGEX_AVOID_UCHAR_H option
 	This is for GNU Emacs, where the regex code is only auxiliary,
 	probably not enough to justify the hassle of incorporating
diff --git a/lib/regex_internal.c b/lib/regex_internal.c
index ad1b273546..e5e5be84bd 100644
--- a/lib/regex_internal.c
+++ b/lib/regex_internal.c
@@ -1285,7 +1285,13 @@ re_node_set_insert (re_node_set *set, Idx elem)
   else
     {
       for (idx = set->nelem; set->elems[idx - 1] > elem; idx--)
-	set->elems[idx] = set->elems[idx - 1];
+        {
+          set->elems[idx] = set->elems[idx - 1];
+          /* Although we already guaranteed that idx is at least 2 here,
+             add an assertion to pacify GCC 16.1.1 -Wanalyzer-out-of-bounds
+             when _REGEX_AVOID_UCHAR_H is defined.  */
+          DEBUG_ASSERT (1 < idx);
+        }
       /* Already in set.  Return early.  */
       if (__glibc_unlikely (set->elems[idx - 1] == elem))
 	return true;
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.