fix overflow of integer types when writing large unsigned long longs to JSON

This commit is contained in:
Graham Lee 2017-11-25 21:23:46 +00:00
parent 4b56172ac8
commit 05184a7e1a
2 changed files with 12 additions and 1 deletions

View file

@ -945,12 +945,17 @@ writeObject(id obj, NSMutableString *output, NSInteger tabs)
{
const char *t = [obj objCType];
if (strchr("cCsSiIlLqQ", *t) != 0)
if (strchr("csilq", *t) != 0)
{
long long i = [(NSNumber*)obj longLongValue];
[output appendFormat: @"%lld", i];
}
else if (strchr("CSILQ", *t) != 0)
{
unsigned long long u = [(NSNumber *)obj unsignedLongLongValue];
[output appendFormat: @"%llu", u];
}
else
{
[output appendFormat: @"%.17g", [(NSNumber*)obj doubleValue]];