]> granicus.if.org Git - clang/commitdiff
[analyzer] Fixup to r158958.
authorAnna Zaks <ganna@apple.com>
Fri, 22 Jun 2012 22:08:09 +0000 (22:08 +0000)
committerAnna Zaks <ganna@apple.com>
Fri, 22 Jun 2012 22:08:09 +0000 (22:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159037 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/MallocChecker.cpp
test/Analysis/malloc.mm
test/Analysis/system-header-simulator-objc.h

index 35c6073bca7d3e90a6b7862f32ee0cfeada4ee27..b0fcb2507954574b6437ff451dcacd325c85f5aa 100644 (file)
@@ -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;
index 23297ec97cbd8556a6151246040240386f863772..64135b2366a279ea68f3a2a6edf317c4b87a60b3 100644 (file)
@@ -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
index 20a26cdbaaa7b44a2bce91e3244f79b2af36e780..a647b3740406de49af506af5c76f41de26322e7b 100644 (file)
@@ -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 <NSCopying, NSMutableCopying, NSCoding>  - (NSUInteger)length;
 + (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length;
 + (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b;