OFString: Fix parsing LLONG_MIN
FossilOrigin-Name: 6f7cdf414a32b65fb7bb40f834156898e77bb6901af75dd02afbf4cbb3aa2233
This commit is contained in:
parent
41d11f0f19
commit
0832f23368
2 changed files with 18 additions and 6 deletions
|
@ -2385,7 +2385,7 @@ OF_SINGLETON_METHODS
|
|||
void *pool = objc_autoreleasePoolPush();
|
||||
const char *UTF8String = self.UTF8String;
|
||||
bool negative = false;
|
||||
long long value = 0;
|
||||
unsigned long long value = 0;
|
||||
|
||||
while (OFASCIIIsSpace(*UTF8String))
|
||||
UTF8String++;
|
||||
|
@ -2437,18 +2437,26 @@ OF_SINGLETON_METHODS
|
|||
if (c >= base)
|
||||
@throw [OFInvalidFormatException exception];
|
||||
|
||||
if (LLONG_MAX / base < value || LLONG_MAX - (value * base) < c)
|
||||
if (ULLONG_MAX / base < value ||
|
||||
ULLONG_MAX - (value * base) < c)
|
||||
@throw [OFOutOfRangeException exception];
|
||||
|
||||
value = (value * base) + c;
|
||||
}
|
||||
|
||||
if (negative)
|
||||
value *= -1;
|
||||
|
||||
objc_autoreleasePoolPop(pool);
|
||||
|
||||
return value;
|
||||
if (negative) {
|
||||
if (value > -(unsigned long long)LLONG_MIN)
|
||||
@throw [OFOutOfRangeException exception];
|
||||
|
||||
return (long long)-value;
|
||||
} else {
|
||||
if (value > (unsigned long long)LLONG_MAX)
|
||||
@throw [OFOutOfRangeException exception];
|
||||
|
||||
return (long long)value;
|
||||
}
|
||||
}
|
||||
|
||||
- (unsigned long long)unsignedLongLongValue
|
||||
|
|
|
@ -749,6 +749,10 @@ static const char *range80ToFF =
|
|||
|
||||
OTAssertEqual([[self.stringClass stringWithString:
|
||||
@"\t\t\r\n"] longLongValueWithBase: 8], 0);
|
||||
|
||||
OTAssertEqual([[self.stringClass stringWithString:
|
||||
([OFString stringWithFormat: @"%lld", LLONG_MIN])] longLongValue],
|
||||
LLONG_MIN);
|
||||
}
|
||||
|
||||
- (void)testLongLongValueThrowsOnInvalidFormat
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue