1// RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.NSError,osx.coreFoundation.CFError -analyzer-store=region -analyzer-constraints=range -verify -Wno-objc-root-class %s
2
3
4typedef signed char BOOL;
5typedef int NSInteger;
6typedef struct _NSZone NSZone;
7@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
8@protocol NSObject  - (BOOL)isEqual:(id)object; @end
9@protocol NSCopying  - (id)copyWithZone:(NSZone *)zone; @end
10@protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder; @end
11@interface NSObject <NSObject> {} @end
12@class NSDictionary;
13@interface NSError : NSObject <NSCopying, NSCoding> {}
14+ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)dict;
15@end
16extern NSString * const NSXMLParserErrorDomain ;
17
18@interface A
19- (void)myMethodWhichMayFail:(NSError **)error;
20- (BOOL)myMethodWhichMayFail2:(NSError **)error;
21@end
22
23@implementation A
24- (void)myMethodWhichMayFail:(NSError **)error {   // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occurred}}
25  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference}}
26}
27
28- (BOOL)myMethodWhichMayFail2:(NSError **)error {  // no-warning
29  if (error) *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning
30  return 0;
31}
32@end
33
34struct __CFError {};
35typedef struct __CFError* CFErrorRef;
36
37void foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred}}
38  *error = 0;  // expected-warning {{Potential null dereference}}
39}
40
41int f1(CFErrorRef* error) {
42  if (error) *error = 0; // no-warning
43  return 0;
44}
45
46int f2(CFErrorRef* error) {
47  if (0 != error) *error = 0; // no-warning
48  return 0;
49}
50
51int f3(CFErrorRef* error) {
52  if (error != 0) *error = 0; // no-warning
53  return 0;
54}
55
56
57