tools: board: Modify integer parser from strtol to strtoll 51/320951/1
authorSangYoun Kwak <sy.kwak@samsung.com>
Mon, 25 Nov 2024 08:08:06 +0000 (17:08 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Tue, 26 Nov 2024 04:06:21 +0000 (13:06 +0900)
Previously in the integer parsing code, the string is parsed using
strtol and the result is checked by comparing with INT_MAX and INT_MIN
to check it is in the "int" type range.

But this method can cause "always false" issue in the 32-bit environment
since the size of long(return type of strl) is same as int in the 32-bit
environment.

To solve this issue, strtol is replaced by strtoll, which returns long
long type that has always 64-bit size in the 32-bit and 64-bit
environment.

According to the change of type, a variable which will contain the
return value of strtoll is renamed.

Change-Id: Iae7df2f226369818d425ae27dd6a3d40f9c784fd
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
tools/board/set-upgrade-progress-status.c

index d493539f9ed364aab51098b9452f1d88bc1b0a5a..8a586ba44e09f315abf48d7896b36acfdfc8d93b 100644 (file)
 static int parse_integer(const char *str, int *val)
 {
        char *endptr = NULL;
-       long longval = 0;
+       long long parsed_long_long = 0;
 
        errno = 0;
-       longval = strtol(str, &endptr, 10);
+       parsed_long_long = strtoll(str, &endptr, 10);
 
        if(errno || *endptr) {
                errno = 0;
                return -EINVAL;
        }
 
-       if(longval > INT_MAX || longval < INT_MIN) {
+       if(parsed_long_long > INT_MAX || parsed_long_long < INT_MIN) {
                return -EINVAL;
        }
 
-       *val = (int)longval;
+       *val = (int)parsed_long_long;
 
        return 0;
 }