From f00e4d030c9dd49e40a8fa08fcae0c1a1be5cf14 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Mon, 29 Jan 2024 20:44:12 +0900 Subject: Fix overflow issue Overflowed constant (INTEGER_OVERFLOW) overflow_const: Expression *out, which is equal to 3161, where *out * 16 + c - offset is known to be equal to 89, overflows the type that receives it, an unsigned integer 8 bits wide. Change-Id: I81fc7a20558c9b78f5c56647ae99c65189e42360 Signed-off-by: Jihoon Kim --- src/scanner-utils.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/scanner-utils.h b/src/scanner-utils.h index 674ecaa..e6cd192 100644 --- a/src/scanner-utils.h +++ b/src/scanner-utils.h @@ -203,11 +203,14 @@ static inline bool scanner_hex(struct scanner *s, uint8_t *out) { int i; + unsigned int result = 0; for (i = 0, *out = 0; is_xdigit(scanner_peek(s)) && i < 2; i++) { const char c = scanner_next(s); const char offset = (c >= '0' && c <= '9' ? '0' : c >= 'a' && c <= 'f' ? 'a' - 10 : 'A' - 10); - *out = *out * 16 + c - offset; + + result = *out * 16 + c - offset; + *out = (uint8_t)result; } return i > 0; } -- cgit v1.2.3