* lib/regex_internal.h: Include stdckdint.h.
* lib/regexec.c (re_search_2_stub):
* modules/regex (Depends-on): Add stdckdint.
Prefer stdckdint.h to intprops.h macros.
---
 ChangeLog            | 6 ++++++
 lib/regex_internal.h | 1 +
 lib/regexec.c        | 2 +-
 modules/regex        | 1 +
 4 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 3528faf40e..55f010adac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2023-05-01  Paul Eggert  <egg...@cs.ucla.edu>
 
+       regex: prefer C23 style overflow checking
+       * lib/regex_internal.h: Include stdckdint.h.
+       * lib/regexec.c (re_search_2_stub):
+       * modules/regex (Depends-on): Add stdckdint.
+       Prefer stdckdint.h to intprops.h macros.
+
        dynarray: prefer C23 style overflow checking
        * lib/malloc/dynarray_emplace_enlarge.c, lib/malloc/dynarray_resize.c:
        Include stdckdint.h, not intprops.h.
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index ae9257eac0..0270091df7 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -29,6 +29,7 @@
 #include <locale.h>
 #include <wchar.h>
 #include <wctype.h>
+#include <stdckdint.h>
 #include <stdint.h>
 
 #ifndef _LIBC
diff --git a/lib/regexec.c b/lib/regexec.c
index 13e0349e72..f05f38ae0e 100644
--- a/lib/regexec.c
+++ b/lib/regexec.c
@@ -324,7 +324,7 @@ re_search_2_stub (struct re_pattern_buffer *bufp, const 
char *string1,
   char *s = NULL;
 
   if (__glibc_unlikely ((length1 < 0 || length2 < 0 || stop < 0
-                        || INT_ADD_WRAPV (length1, length2, &len))))
+                        || ckd_add (&len, length1, length2))))
     return -2;
 
   /* Concatenate the strings.  */
diff --git a/modules/regex b/modules/regex
index dfe0c2918e..e38479858f 100644
--- a/modules/regex
+++ b/modules/regex
@@ -35,6 +35,7 @@ mbrtowc                 [test $ac_use_included_regex = yes]
 mbsinit                 [test $ac_use_included_regex = yes]
 nl_langinfo             [test $ac_use_included_regex = yes]
 stdbool                 [test $ac_use_included_regex = yes]
+stdckdint               [test $ac_use_included_regex = yes]
 stdint                  [test $ac_use_included_regex = yes]
 verify                  [test $ac_use_included_regex = yes]
 wchar                   [test $ac_use_included_regex = yes]
-- 
2.39.2


Reply via email to