blob: 6de98e85efe3081d50cff6a03d16001cd2e028b6 [file] [log] [blame]
Dominic Chen184c6242017-03-03 18:02:02 +00001// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.NSError,osx.coreFoundation.CFError -analyzer-store=region -verify -Wno-objc-root-class %s
Ted Kremenekb5351812009-02-17 04:27:41 +00002
Ted Kremenek55bec4d2008-09-19 04:56:32 +00003
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
Ted Kremenekf368fa62009-08-06 06:26:40 +000024- (void)myMethodWhichMayFail:(NSError **)error { // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occurred}}
Ted Kremenek9bf9af92012-08-16 17:45:23 +000025 *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference}}
Ted Kremenek55bec4d2008-09-19 04:56:32 +000026}
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
Ted Kremenek3aa89a92008-10-01 23:24:09 +000033
34struct __CFError {};
35typedef struct __CFError* CFErrorRef;
36
Ted Kremenekf368fa62009-08-06 06:26:40 +000037void foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred}}
Ted Kremenek9bf9af92012-08-16 17:45:23 +000038 *error = 0; // expected-warning {{Potential null dereference}}
Ted Kremenek3aa89a92008-10-01 23:24:09 +000039}
40
Ted Kremenek035cf932009-03-28 19:59:33 +000041int f1(CFErrorRef* error) {
42 if (error) *error = 0; // no-warning
Ted Kremenek3aa89a92008-10-01 23:24:09 +000043 return 0;
44}
Ted Kremenek035cf932009-03-28 19:59:33 +000045
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