From 3e4f65d863bff9c4bbb2e7061a5d69b8c0366d66 Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Fri, 22 Jun 2012 22:08:09 +0000 Subject: [PATCH] [analyzer] Fixup to r158958. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159037 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 4 ++-- test/Analysis/malloc.mm | 5 +++++ test/Analysis/system-header-simulator-objc.h | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 35c6073bca..b0fcb25079 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -482,7 +482,7 @@ void MallocChecker::checkPostStmt(const CallExpr *CE, CheckerContext &C) const { } static bool isFreeWhenDoneSetToZero(CallOrObjCMessage Call, Selector &S) { - for (unsigned i = 1; i < Call.getNumArgs(); ++i) + for (unsigned i = 1; i < S.getNumArgs(); ++i) if (S.getNameForSlot(i).equals("freeWhenDone")) if (Call.getArgSVal(i).isConstant(0)) return true; @@ -1435,7 +1435,7 @@ bool MallocChecker::doesNotFreeMemory(const CallOrObjCMessage *Call, // White list the ObjC functions which do free memory. // - Anything containing 'freeWhenDone' param set to 1. // Ex: dataWithBytesNoCopy:length:freeWhenDone. - for (unsigned i = 1; i < Call->getNumArgs(); ++i) { + for (unsigned i = 1; i < S.getNumArgs(); ++i) { if (S.getNameForSlot(i).equals("freeWhenDone")) { if (Call->getArgSVal(i).isConstant(1)) return false; diff --git a/test/Analysis/malloc.mm b/test/Analysis/malloc.mm index 23297ec97c..64135b2366 100644 --- a/test/Analysis/malloc.mm +++ b/test/Analysis/malloc.mm @@ -206,4 +206,9 @@ void foo(NSPointerArray* pointerArray) { // Freeing the buffer is allowed. void* buffer = [pointerArray pointerAtIndex:0]; free(buffer); +} + +void noCrashOnVariableArgumentSelector() { + NSMutableString *myString = [NSMutableString stringWithString:@"some text"]; + [myString appendFormat:@"some text = %d", 3]; } \ No newline at end of file diff --git a/test/Analysis/system-header-simulator-objc.h b/test/Analysis/system-header-simulator-objc.h index 20a26cdbaa..a647b37404 100644 --- a/test/Analysis/system-header-simulator-objc.h +++ b/test/Analysis/system-header-simulator-objc.h @@ -85,7 +85,13 @@ typedef double NSTimeInterval; - (id)initWithBytes:(const void *)bytes length:(NSUInteger)len encoding:(NSStringEncoding)encoding; - (id)initWithBytesNoCopy:(void *)bytes length:(NSUInteger)len encoding:(NSStringEncoding)encoding freeWhenDone:(BOOL)freeBuffer; + (id)stringWithUTF8String:(const char *)nullTerminatedCString; ++ (id)stringWithString:(NSString *)string; @end @class NSString, NSURL, NSError; + +@interface NSMutableString : NSString +- (void)appendFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2))); +@end + @interface NSData : NSObject - (NSUInteger)length; + (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length; + (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b; -- 2.40.0