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

@ -1,3 +1,9 @@
2017-11-25 Graham Lee <graham@iamleeg.com>
* Source/NSJSONSerialization.m: Fix for bug #12 on github. This
makes sure that unsigned integer types are written as such,
avoiding a potential overflow.
2017-11-16 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSArray.m: Fix for bug reported on github by zneak.

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