summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2023-01-21 10:18:15 +0000
committerrillig <rillig@NetBSD.org>2023-01-21 10:18:15 +0000
commit4d22fe17dfd6cd854cd7390ba0bbce36ae5a66ee (patch)
tree47575948869b7bab120c82f0fc06586d08682860 /usr.bin
parent87a180d996bee936d17ea5ac04add09a62d62cec (diff)
lint: use simpler integers for parsing hex escapes
No functional change.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/xlint/lint1/lex.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/usr.bin/xlint/lint1/lex.c b/usr.bin/xlint/lint1/lex.c
index 5b436c7ac90..0bccd151a1f 100644
--- a/usr.bin/xlint/lint1/lex.c
+++ b/usr.bin/xlint/lint1/lex.c
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.139 2023/01/21 10:11:41 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.140 2023/01/21 10:18:15 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.139 2023/01/21 10:11:41 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.140 2023/01/21 10:18:15 rillig Exp $");
#endif
#include <ctype.h>
@@ -770,18 +770,18 @@ read_escaped_hex(int c)
/* \x undefined in traditional C */
warning(82);
int value = 0;
- int state = 0; /* 0 = no digits, 1 = OK, -1 = overflow */
+ int state = 0; /* 0 = no digits, 1 = OK, 2 = overflow */
while (c = read_byte(), isxdigit(c)) {
c = isdigit(c) ? c - '0' : toupper(c) - 'A' + 10;
value = (value << 4) + c;
- if (state >= 0) {
- if ((value & ~CHAR_MASK) != 0) {
- /* overflow in hex escape */
- warning(75);
- state = -1;
- } else {
- state = 1;
- }
+ if (state == 2)
+ continue;
+ if ((value & ~CHAR_MASK) != 0) {
+ /* overflow in hex escape */
+ warning(75);
+ state = 2;
+ } else {
+ state = 1;
}
}
prev_byte = c;
@@ -789,7 +789,7 @@ read_escaped_hex(int c)
/* no hex digits follow \x */
error(74);
}
- if (state == -1)
+ if (state == 2)
value &= CHAR_MASK;
return value;
}