CFRetainRelease_NSAssertionHandler.m revision 033a07e5fca459ed184369cfee7c90d82367a93a
1// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core -verify %s -analyzer-constraints=basic -analyzer-store=region 2// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core -verify %s -analyzer-constraints=range -analyzer-store=region 3 4typedef struct objc_selector *SEL; 5typedef signed char BOOL; 6typedef int NSInteger; 7typedef unsigned int NSUInteger; 8typedef struct _NSZone NSZone; 9@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; 10@protocol NSObject - (BOOL)isEqual:(id)object; @end 11@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end 12@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end 13@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end 14@interface NSObject <NSObject> {} - (id)init; @end 15extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); 16@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> 17- (NSUInteger)length; 18+ (id)stringWithUTF8String:(const char *)nullTerminatedCString; 19@end extern NSString * const NSBundleDidLoadNotification; 20@interface NSAssertionHandler : NSObject {} 21+ (NSAssertionHandler *)currentHandler; 22- (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(NSInteger)line description:(NSString *)format,...; 23@end 24extern NSString * const NSConnectionReplyMode; 25 26//----------------------------------------------------------------------------// 27// The following test case was filed in PR 2593: 28// http://llvm.org/bugs/show_bug.cgi?id=2593 29// 30// There should be no null dereference flagged by the checker because of 31// NSParameterAssert and NSAssert. 32 33 34@interface TestAssert : NSObject {} 35@end 36 37@implementation TestAssert 38 39- (id)initWithPointer: (int*)x 40{ 41 // Expansion of: NSParameterAssert( x != 0 ); 42 do { if (!((x != 0))) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:"CFRetainRelease_NSAssertionHandler.m"] lineNumber:21 description:(@"Invalid parameter not satisfying: %s"), ("x != 0"), (0), (0), (0), (0)]; } } while(0); 43 44 if( (self = [super init]) != 0 ) 45 { 46 *x = 1; // no-warning 47 } 48 49 return self; 50} 51 52- (id)initWithPointer2: (int*)x 53{ 54 // Expansion of: NSAssert( x != 0, @"" ); 55 do { if (!((x != 0))) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:"CFRetainRelease_NSAssertionHandler.m"] lineNumber:33 description:((@"")), (0), (0), (0), (0), (0)]; } } while(0); 56 57 if( (self = [super init]) != 0 ) 58 { 59 *x = 1; // no-warning 60 } 61 62 return self; 63} 64 65@end 66