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;
|
const char *s;
|
||||||
unsigned long long acc;
|
unsigned long long acc;
|
||||||
|
long long ret = 0;
|
||||||
char c;
|
char c;
|
||||||
unsigned long long cutoff;
|
unsigned long long cutoff;
|
||||||
int neg, any, cutlim;
|
int neg, any, cutlim;
|
||||||
@@ -135,15 +136,14 @@ strtoll(const char * nptr, char ** endptr, int base)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (any < 0) {
|
if (any < 0) {
|
||||||
acc = neg ? LLONG_MIN : LLONG_MAX;
|
ret = neg ? LLONG_MIN : LLONG_MAX;
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
} else if (!any) {
|
} else if (!any) {
|
||||||
noconv:
|
noconv:
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
} else if (neg)
|
} else if (neg)
|
||||||
acc = -acc;
|
ret = -(long long)acc;
|
||||||
if (endptr != NULL)
|
if (endptr != NULL)
|
||||||
*endptr = (char *)(any ? s - 1 : nptr);
|
*endptr = (char *)(any ? s - 1 : nptr);
|
||||||
return (acc);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user