Fix issues detected by static analysis tool 91/305891/4 accepted/tizen_unified accepted/tizen_unified_toolchain accepted/tizen_unified_x tizen accepted/tizen/unified/20240219.160452 accepted/tizen/unified/toolchain/20240311.070033 accepted/tizen/unified/x/20240220.150017
authorJihoon Kim <jihoon48.kim@samsung.com>
Tue, 13 Feb 2024 01:33:20 +0000 (10:33 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Mon, 19 Feb 2024 05:36:46 +0000 (14:36 +0900)
Change-Id: I1dc356839dd3af7141df7dc727d58aa782b69da0
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/scanner-utils.h
test/common.c

index e6cd192..3be8392 100644 (file)
@@ -203,14 +203,13 @@ 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);
 
-        result = *out * 16 + c - offset;
-        *out = (uint8_t)result;
+        if (*out * 16 + c >= offset)
+            *out = *out * 16 + c - offset;
     }
     return i > 0;
 }
index cb911e8..0bed3de 100644 (file)
@@ -260,7 +260,7 @@ test_read_file(const char *path_rel)
 
     remaining = info.st_size;
     tmp = ret;
-    while ((count = read(fd, tmp, remaining))) {
+    while ((count = read(fd, tmp, remaining)) > 0) {
         remaining -= count;
         tmp += count;
     }