潜在的空解除引用
我正在使用开源 json 解析器,但在编译它时给我取消引用警告。
MyProject/Classes/SBJSON.m:403:13 潜在的空取消引用。根据“创建和返回 NSError 对象”中的编码标准,参数“error”
- (BOOL)scanValue:(NSObject **)o error:(NSError **)error
{
skipWhitespace(c);
switch (*c++) {
case '{':
return [self scanRestOfDictionary:(NSMutableDictionary **)o error:error];
break;
case '[':
return [self scanRestOfArray:(NSMutableArray **)o error:error];
break;
case '"':
return [self scanRestOfString:(NSMutableString **)o error:error];
break;
case 'f':
return [self scanRestOfFalse:(NSNumber **)o error:error];
break;
case 't':
return [self scanRestOfTrue:(NSNumber **)o error:error];
break;
case 'n':
return [self scanRestOfNull:(NSNull **)o error:error];
break;
case '-':
case '0'...'9':
c--; // cannot verify number correctly without the first character
return [self scanNumber:(NSNumber **)o error:error];
break;
case '+':
*error = err(EPARSENUM, @"Leading + disallowed in number");
return NO;
break;
case 0x0:
*error = err(EEOF, @"Unexpected end of string");
return NO;
break;
default:
*error = err(EPARSE, @"Unrecognised leading character");
return NO;
break;
}
NSAssert(0, @"Should never get here");
return NO;
}
在这里可能为 null,它显示错误时取消引用。
I am using an open-source json parser, but while compiling its giving me dereferencing warnings.
MyProject/Classes/SBJSON.m:403:13 Potential null dereference. According to coding standards in 'Creating and Returning NSError Objects' the parameter 'error' may be null
- (BOOL)scanValue:(NSObject **)o error:(NSError **)error
{
skipWhitespace(c);
switch (*c++) {
case '{':
return [self scanRestOfDictionary:(NSMutableDictionary **)o error:error];
break;
case '[':
return [self scanRestOfArray:(NSMutableArray **)o error:error];
break;
case '"':
return [self scanRestOfString:(NSMutableString **)o error:error];
break;
case 'f':
return [self scanRestOfFalse:(NSNumber **)o error:error];
break;
case 't':
return [self scanRestOfTrue:(NSNumber **)o error:error];
break;
case 'n':
return [self scanRestOfNull:(NSNull **)o error:error];
break;
case '-':
case '0'...'9':
c--; // cannot verify number correctly without the first character
return [self scanNumber:(NSNumber **)o error:error];
break;
case '+':
*error = err(EPARSENUM, @"Leading + disallowed in number");
return NO;
break;
case 0x0:
*error = err(EEOF, @"Unexpected end of string");
return NO;
break;
default:
*error = err(EPARSE, @"Unrecognised leading character");
return NO;
break;
}
NSAssert(0, @"Should never get here");
return NO;
}
here it shows dereferencing at error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它抱怨错误参数可能为 NULL(如果调用者选择传递 NULL)。然后,该语句
将崩溃。 r报告的解决方法是在赋值周围放置一个 if 语句:
It complains that the error parameter might be NULL (in case the caller choses to pass NULL). Then, the statement
will crash. A reported work-around is to put an if statement around the assignment: