Skip to content

Commit f3ed599

Browse files
committed
Update README.md with additional information and bring it up to date with the 1.4 changes.
1 parent f520db7 commit f3ed599

2 files changed

Lines changed: 65 additions & 38 deletions

File tree

JSONKit.m

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ static int jk_parse_number(JKParseState *parseState) {
17231723
if(JK_EXPECT_F(parseState->token.tokenPtrRange.length == 2UL) && JK_EXPECT_F(numberTempBuf[1] == '0') && JK_EXPECT_F(isNegative)) { isFloatingPoint = 1; }
17241724

17251725
if(isFloatingPoint) {
1726-
parseState->token.value.number.doubleValue = strtod((const char *)numberTempBuf, (char **)&endOfNumber);
1726+
parseState->token.value.number.doubleValue = strtod((const char *)numberTempBuf, (char **)&endOfNumber); // strtod is documented to return U+2261 (identical to) 0.0 on an underflow error (along with setting errno to ERANGE).
17271727
parseState->token.value.type = JKValueTypeDouble;
17281728
parseState->token.value.ptrRange.ptr = (const unsigned char *)&parseState->token.value.number.doubleValue;
17291729
parseState->token.value.ptrRange.length = sizeof(double);
@@ -1748,10 +1748,10 @@ static int jk_parse_number(JKParseState *parseState) {
17481748
numberState = JSONNumberStateError;
17491749
if(errno == ERANGE) {
17501750
switch(parseState->token.value.type) {
1751-
case JKValueTypeDouble: jk_error(parseState, @"The value '%s' could not be represented as a 'double' due to %s.", numberTempBuf, (parseState->token.value.number.doubleValue == 0.0) ? "underflow" : "overflow"); break;
1752-
case JKValueTypeLongLong: jk_error(parseState, @"The value '%s' exceeded the minimum value that could be represented: %lld.", numberTempBuf, parseState->token.value.number.longLongValue); break;
1753-
case JKValueTypeUnsignedLongLong: jk_error(parseState, @"The value '%s' exceeded the maximum value that could be represented: %llu.", numberTempBuf, parseState->token.value.number.unsignedLongLongValue); break;
1754-
default: jk_error(parseState, @"Internal error: Unknown token value type. %@ line #%ld", [NSString stringWithUTF8String:__FILE__], (long)__LINE__); break;
1751+
case JKValueTypeDouble: jk_error(parseState, @"The value '%s' could not be represented as a 'double' due to %s.", numberTempBuf, (parseState->token.value.number.doubleValue == 0.0) ? "underflow" : "overflow"); break; // see above for == 0.0.
1752+
case JKValueTypeLongLong: jk_error(parseState, @"The value '%s' exceeded the minimum value that could be represented: %lld.", numberTempBuf, parseState->token.value.number.longLongValue); break;
1753+
case JKValueTypeUnsignedLongLong: jk_error(parseState, @"The value '%s' exceeded the maximum value that could be represented: %llu.", numberTempBuf, parseState->token.value.number.unsignedLongLongValue); break;
1754+
default: jk_error(parseState, @"Internal error: Unknown token value type. %@ line #%ld", [NSString stringWithUTF8String:__FILE__], (long)__LINE__); break;
17551755
}
17561756
}
17571757
}
@@ -1950,12 +1950,8 @@ static void jk_error_parse_accept_or3(JKParseState *parseState, int state, NSStr
19501950
if(JK_EXPECT_F((key = jk_object_for_token(parseState)) == NULL)) { jk_error(parseState, @"Internal error: Key == NULL."); stopParsing = 1; break; }
19511951
else {
19521952
parseState->objectStack.keys[objectStackIndex] = key;
1953-
if(JK_EXPECT_T(parseState->token.value.cacheItem != NULL)) {
1954-
if((parseState->token.value.cacheItem->cfHash == 0UL)) { parseState->token.value.cacheItem->cfHash = CFHash(key); }
1955-
parseState->objectStack.cfHashes[objectStackIndex] = parseState->token.value.cacheItem->cfHash;
1956-
} else {
1957-
parseState->objectStack.cfHashes[objectStackIndex] = CFHash(key);
1958-
}
1953+
if(JK_EXPECT_T(parseState->token.value.cacheItem != NULL)) { if(JK_EXPECT_F(parseState->token.value.cacheItem->cfHash == 0UL)) { parseState->token.value.cacheItem->cfHash = CFHash(key); } parseState->objectStack.cfHashes[objectStackIndex] = parseState->token.value.cacheItem->cfHash; }
1954+
else { parseState->objectStack.cfHashes[objectStackIndex] = CFHash(key); }
19591955
}
19601956
break;
19611957

@@ -2327,7 +2323,7 @@ - (id)objectWithData:(NSData *)jsonData
23272323

23282324
- (id)objectWithData:(NSData *)jsonData error:(NSError **)error
23292325
{
2330-
if(jsonData == NULL) { [NSException raise:NSInvalidArgumentException format:@"The jsonData argument is NULL."]; }
2326+
if(jsonData == NULL) { [NSException raise:NSInvalidArgumentException format:@"The jsonData argument is NULL."]; }
23312327
return([self objectWithUTF8String:(const unsigned char *)[jsonData bytes] length:[jsonData length] error:error]);
23322328
}
23332329

@@ -2352,7 +2348,7 @@ - (id)mutableObjectWithData:(NSData *)jsonData
23522348

23532349
- (id)mutableObjectWithData:(NSData *)jsonData error:(NSError **)error
23542350
{
2355-
if(jsonData == NULL) { [NSException raise:NSInvalidArgumentException format:@"The jsonData argument is NULL."]; }
2351+
if(jsonData == NULL) { [NSException raise:NSInvalidArgumentException format:@"The jsonData argument is NULL."]; }
23562352
return([self mutableObjectWithUTF8String:(const unsigned char *)[jsonData bytes] length:[jsonData length] error:error]);
23572353
}
23582354

@@ -2668,8 +2664,8 @@ static int jk_encode_add_atom_to_buffer(JKEncodeState *encodeState, void *object
26682664
{
26692665
const unsigned char *cStringPtr = (const unsigned char *)CFStringGetCStringPtr((CFStringRef)object, kCFStringEncodingMacRoman);
26702666
if(cStringPtr != NULL) {
2671-
size_t utf8Idx = 0UL;
26722667
const unsigned char *utf8String = cStringPtr;
2668+
size_t utf8Idx = 0UL;
26732669

26742670
CFIndex stringLength = CFStringGetLength((CFStringRef)object);
26752671
if(JK_EXPECT_F(((encodeState->atIndex + (stringLength * 2UL) + 256UL) > encodeState->stringBuffer.bytes.length)) && JK_EXPECT_F((jk_managedBuffer_resize(&encodeState->stringBuffer, encodeState->atIndex + (stringLength * 2UL) + 1024UL) == NULL))) { jk_encode_error(encodeState, @"Unable to resize temporary buffer."); return(1); }
@@ -2766,7 +2762,9 @@ static int jk_encode_add_atom_to_buffer(JKEncodeState *encodeState, void *object
27662762
int isNegative = 0;
27672763
unsigned long long ullv;
27682764
long long llv;
2769-
2765+
2766+
if(JK_EXPECT_F(objCType == NULL) || JK_EXPECT_F(objCType[0] == 0) || JK_EXPECT_F(objCType[1] != 0)) { jk_encode_error(encodeState, @"NSNumber conversion error, unknown type. Type: '%s'", (objCType == NULL) ? "<NULL>" : objCType); return(1); }
2767+
27702768
switch(objCType[0]) {
27712769
case 'c': case 'i': case 's': case 'l': case 'q':
27722770
if(JK_EXPECT_T(CFNumberGetValue((CFNumberRef)object, kCFNumberLongLongType, &llv))) {

0 commit comments

Comments
 (0)