Module Name: src
Committed By: christos
Date: Wed Jan 1 18:19:50 UTC 2025
Modified Files:
src/lib/libc/regex: regcomp.c regex2.h
Log Message:
PR/58910: enh at google dot com: Fix signed character issue in character
ranges.
To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/lib/libc/regex/regcomp.c
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/regex/regex2.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/regex/regcomp.c
diff -u src/lib/libc/regex/regcomp.c:1.48 src/lib/libc/regex/regcomp.c:1.49
--- src/lib/libc/regex/regcomp.c:1.48 Wed Aug 30 16:37:24 2023
+++ src/lib/libc/regex/regcomp.c Wed Jan 1 13:19:50 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: regcomp.c,v 1.48 2023/08/30 20:37:24 christos Exp $ */
+/* $NetBSD: regcomp.c,v 1.49 2025/01/01 18:19:50 christos Exp $ */
/*-
* SPDX-License-Identifier: BSD-3-Clause
@@ -51,7 +51,7 @@
static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94";
__FBSDID("$FreeBSD: head/lib/libc/regex/regcomp.c 368359 2020-12-05 03:18:48Z kevans $");
#endif
-__RCSID("$NetBSD: regcomp.c,v 1.48 2023/08/30 20:37:24 christos Exp $");
+__RCSID("$NetBSD: regcomp.c,v 1.49 2025/01/01 18:19:50 christos Exp $");
#ifndef LIBHACK
#define REGEX_GNU_EXTENSIONS
@@ -1764,8 +1764,7 @@ CHadd(struct parse *p, cset *cs, wint_t
_DIAGASSERT(p != NULL);
_DIAGASSERT(cs != NULL);
- assert(ch >= 0);
- if (ch < NC)
+ if ((unsigned)ch < NC)
cs->bmp[(unsigned)ch >> 3] |= 1 << (ch & 7);
else {
newwides = reallocarray(cs->wides, cs->nwides + 1,
@@ -1778,9 +1777,9 @@ CHadd(struct parse *p, cset *cs, wint_t
cs->wides[cs->nwides++] = ch;
}
if (cs->icase) {
- if ((nch = towlower(ch)) < NC)
+ if ((unsigned)(nch = towlower(ch)) < NC)
cs->bmp[(unsigned)nch >> 3] |= 1 << (nch & 7);
- if ((nch = towupper(ch)) < NC)
+ if ((unsigned)(nch = towupper(ch)) < NC)
cs->bmp[(unsigned)nch >> 3] |= 1 << (nch & 7);
}
}
Index: src/lib/libc/regex/regex2.h
diff -u src/lib/libc/regex/regex2.h:1.15 src/lib/libc/regex/regex2.h:1.16
--- src/lib/libc/regex/regex2.h:1.15 Wed Feb 24 13:13:21 2021
+++ src/lib/libc/regex/regex2.h Wed Jan 1 13:19:50 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: regex2.h,v 1.15 2021/02/24 18:13:21 christos Exp $ */
+/* $NetBSD: regex2.h,v 1.16 2025/01/01 18:19:50 christos Exp $ */
/*-
* SPDX-License-Identifier: BSD-3-Clause
@@ -135,8 +135,7 @@ CHIN1(cset *cs, wint_t ch)
{
unsigned int i;
- assert(ch >= 0);
- if (ch < NC)
+ if ((unsigned)ch < NC)
return (((cs->bmp[(unsigned)ch >> 3] & (1 << (ch & 7))) != 0) ^
cs->invert);
for (i = 0; i < cs->nwides; i++) {
@@ -160,8 +159,7 @@ static __inline int
CHIN(cset *cs, wint_t ch)
{
- assert(ch >= 0);
- if (ch < NC)
+ if ((unsigned)ch < NC)
return (((cs->bmp[(unsigned)ch >> 3] & (1 << (ch & 7))) != 0) ^
cs->invert);
else if (cs->icase)