Fix overflow issue 73/305173/2 accepted/tizen/unified/20240131.064100 accepted/tizen/unified/20240131.064200 accepted/tizen/unified/20240131.064253 accepted/tizen/unified/x/20240205.063940
authorJihoon Kim <jihoon48.kim@samsung.com>
Mon, 29 Jan 2024 11:44:12 +0000 (20:44 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Mon, 29 Jan 2024 11:44:50 +0000 (20:44 +0900)
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 <jihoon48.kim@samsung.com>
src/scanner-utils.h

index 674ecaa..e6cd192 100644 (file)
@@ -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;
 }