将错误分配给错误的指针指针时的潜在空引用

时间:2014-11-20 23:43:31

标签: objective-c c

*perror = error行上进行此操作。即使我将其包裹在if (error)

- (BOOL)validate:(NSError **)perror password:(BOOL)password {
    BOOL ret = YES;

    NSMutableString * errorMessage = [@"" mutableCopy];

    ...other validation code

    NSError * error = [NSError errorWithDomain:@"Profile" code:100 userInfo:dictionary];

    if (error) {
       *perror = error;
    }

    return  ret;
}

1 个答案:

答案 0 :(得分:3)

{p> perror可能是nil。警惕:

if (error && perror) {
    *perror = error;
}