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