JSON Framework — Potential Null Dereference
If you are using json-framework as your preferred iPhone / Cocoa Touch JSON framework then you might find that the SBJSON.m is not necessarily perfect.
Don’t get me wrong, it is an awesome utility and it has saved me heaps of time but when analyzing the code (with XCode 3.2) I got lots (36 or so) of Potential null dereference warnings.
The reason for it is that when this the error is built in lines like this:
*error = err(EUNSUPPORTED, @"JSON object key must be string");
The error object is not checked for NULL.
According to Apple’s documentation one can call a method that takes a error:(NSError**)error parameter with either of these:
NULL
NSError *error = nil;
So if the argument is NULL you can’t really assign something to it.
To fix the XCode warnings (and your code) just do this test before the call to create a new error object.
if (error != NULL) *error = err(EUNSUPPORTED, @"JSON object key must be string");
Cheers…
By Nick | 5. Oct 2009 | Uncategorized | No Comments »
