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>
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;
}