roken: strtoll.c negation is a no-op on unsigned integer
strtoll() returns a signed long long not an unsigned long long. When applying the negation for negatives the value must be cast from unsigned to signed and then stored in a signed variable before returning it. Change-Id: If568afd2509d27c7bf206ca59d32ca150cb34857
This commit is contained in:
@@ -57,6 +57,7 @@ strtoll(const char * nptr, char ** endptr, int base)
|
||||
{
|
||||
const char *s;
|
||||
unsigned long long acc;
|
||||
long long ret = 0;
|
||||
char c;
|
||||
unsigned long long cutoff;
|
||||
int neg, any, cutlim;
|
||||
@@ -135,15 +136,14 @@ strtoll(const char * nptr, char ** endptr, int base)
|
||||
}
|
||||
}
|
||||
if (any < 0) {
|
||||
acc = neg ? LLONG_MIN : LLONG_MAX;
|
||||
ret = neg ? LLONG_MIN : LLONG_MAX;
|
||||
errno = ERANGE;
|
||||
} else if (!any) {
|
||||
noconv:
|
||||
errno = EINVAL;
|
||||
} else if (neg)
|
||||
acc = -acc;
|
||||
ret = -(long long)acc;
|
||||
if (endptr != NULL)
|
||||
*endptr = (char *)(any ? s - 1 : nptr);
|
||||
return (acc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user