Browse files

Add a `#ifdef` to silence a `clang` static analyzer false positive wa…


The current (at the time of this writing) version of the `clang` static analyzer is complaing that the `objects` pointer is `NULL`.  This is a false positive warning from the analyzer.
  • Loading branch information...
1 parent 5663f2d commit 82157634ca0ca5b6a4a67a194dd11f15d9b72835 @johnezang committed Jul 12, 2012
Showing with 2 additions and 0 deletions.
  1. +2 −0 JSONKit.m
@@ -744,7 +744,9 @@ - (void)getObjects:(id *)objectsPtr range:(NSRange)range
NSParameterAssert((objects != NULL) && (count <= capacity));
if((objectsPtr == NULL) && (NSMaxRange(range) > 0UL)) { [NSException raise:NSRangeException format:@"*** -[%@ %@]: pointer to objects array is NULL but range length is %lu", NSStringFromClass([self class]), NSStringFromSelector(_cmd), (unsigned long)NSMaxRange(range)]; }
if((range.location > count) || (NSMaxRange(range) > count)) { [NSException raise:NSRangeException format:@"*** -[%@ %@]: index (%lu) beyond bounds (%lu)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), (unsigned long)NSMaxRange(range), (unsigned long)count]; }
+#ifndef __clang_analyzer__
memcpy(objectsPtr, objects + range.location, range.length * sizeof(id));
- (id)objectAtIndex:(NSUInteger)objectIndex

15 comments on commit 8215763

im afraid I see it as true.. the objectPtr could be NULL and it would crash.
objectPtr = NULL
range = NSMakeRange(1,1)

@Daij-Djan, you could write it as this:
if ((true) && (true)) { raise }

as objectsPtr == NULL will be true
and NSMaxRange of range 1,1 will also be greater then 0

seems like the compiler does not notice throwing an exception will stop the execution right there

@schubter:: yes sorry blush I meant a zero range! (e.g. 1,0) => the idea is that the if doesn't have to trigger ....

@wwwang89 This is not the place to ask such questions. GitHub is for reporting issues and requesting features. If you want to ask technical questions like how to download files from GitHub, either read the git/GitHub documentation or ask this question on a forum such as StackOverflow.

One way to solve this without silencing the analyzer would be to add this at the top of the method:
if (range.length == 0) return;

No need to start copying anything anyway when the range length is 0.

This avoids a crash when calling [getObjects:NULL range:NSMakeRange(0, 0)], which is why the analyzer was complaining in the first place (so no false positive).

JSONKit will crash in the ios9, 'NSTaggedPointString', i can't resolve it

This may not be a useful answer, but why are you still using JSONKit? NSJSONSerialization has been available since iOS 5. There are no iOS devices you should be supporting that can't use it. This library hasn't been update since 2012. It's time to let it go.

@guykogus I know, but my team started use in early, so.. need some time.
now, i still resolve it...

Can you share the JSON string that you're trying to parse?

@guykogus after iOS9.0 ,like '0.4' , system change it become NSTaggedPointString, change '12345678' become CFString, NSTaggedPointString string will crash in the JSONKit, ‘- (NSString *)JSONString’ method.
Do you understand.

No... please provide the JSON string and code you're using.

@guykogus , resolve it just now, #185

I have a fork that handle tagged pointers the right way : see #158.

Please sign in to comment.