git: 56b09feb23d9 - stable/14 - regcomp: use unsigned char when testing for escapes

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Sat, 30 Sep 2023 02:52:19 UTC
The branch stable/14 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=56b09feb23d98fcd0c4aed8d4f907a5a2f6b5ea9

commit 56b09feb23d98fcd0c4aed8d4f907a5a2f6b5ea9
Author:     Christos Zoulas <christos@NetBSD.org>
AuthorDate: 2023-08-30 20:37:24 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2023-09-30 01:40:59 +0000

    regcomp: use unsigned char when testing for escapes
    
    - cast GETNEXT to unsigned where it is being promoted to int to prevent
      sign-extension (really it would have been better for PEEK*() and
      GETNEXT() to return unsigned char; this would have removed a ton of
      (uch) casts, but it is too intrusive for now).
    - fix an isalpha that should have been iswalpha
    
    PR:             264275, 274032
    Reviewed by:    kevans, eugen (previous version)
    Obtained from:  NetBSD
    
    (cherry picked from commit 3fb80f1476c7776f04ba7ef6d08397cef6abcfb0)
---
 lib/libc/regex/regcomp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c
index 791755ceb14d..42fa1b99e58e 100644
--- a/lib/libc/regex/regcomp.c
+++ b/lib/libc/regex/regcomp.c
@@ -828,10 +828,10 @@ p_simp_re(struct parse *p, struct branchc *bc)
 	handled = false;
 
 	assert(MORE());		/* caller should have ensured this */
-	c = GETNEXT();
+	c = (uch)GETNEXT();
 	if (c == '\\') {
 		(void)REQUIRE(MORE(), REG_EESCAPE);
-		cc = GETNEXT();
+		cc = (uch)GETNEXT();
 		c = BACKSL | cc;
 #ifdef LIBREGEX
 		if (p->gnuext) {
@@ -992,7 +992,7 @@ p_count(struct parse *p)
 	int ndigits = 0;
 
 	while (MORE() && isdigit((uch)PEEK()) && count <= DUPMAX) {
-		count = count*10 + (GETNEXT() - '0');
+		count = count*10 + ((uch)GETNEXT() - '0');
 		ndigits++;
 	}
 
@@ -1302,7 +1302,7 @@ may_escape(struct parse *p, const wint_t ch)
 
 	if ((p->pflags & PFLAG_LEGACY_ESC) != 0)
 		return (true);
-	if (isalpha(ch) || ch == '\'' || ch == '`')
+	if (iswalpha(ch) || ch == '\'' || ch == '`')
 		return (false);
 	return (true);
 #ifdef NOTYET