[cfe-commits] r97318 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/format-strings.c test/SemaObjC/format-strings-objc.m

Ted Kremenek kremenek at apple.com
Sat Feb 27 00:34:51 PST 2010


Author: kremenek
Date: Sat Feb 27 02:34:51 2010
New Revision: 97318

URL: http://llvm.org/viewvc/llvm-project?rev=97318&view=rev
Log:
Fix crasher caused by setting a bit in a possibly empty bitvector while
doing printf format string checking.  This is a recent regression.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/Sema/format-strings.c
    cfe/trunk/test/SemaObjC/format-strings-objc.m

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=97318&r1=97317&r2=97318&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Sat Feb 27 02:34:51 2010
@@ -1283,7 +1283,12 @@
 
   // Consume the argument.
   unsigned argIndex = FS.getArgIndex();
-  CoveredArgs.set(argIndex);
+  if (argIndex < NumDataArgs) {
+    // The check to see if the argIndex is valid will come later.
+    // We set the bit here because we may exit early from this
+    // function if we encounter some other error.
+    CoveredArgs.set(argIndex);
+  }
 
   // Check for using an Objective-C specific conversion specifier
   // in a non-ObjC literal.

Modified: cfe/trunk/test/Sema/format-strings.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings.c?rev=97318&r1=97317&r2=97318&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings.c (original)
+++ cfe/trunk/test/Sema/format-strings.c Sat Feb 27 02:34:51 2010
@@ -145,6 +145,7 @@
 }
 
 void test10(int x, float f, int i, long long lli) {
+  printf("%s"); // expected-warning{{more '%' conversions than data arguments}}
   printf("%@", 12); // expected-warning{{invalid conversion specifier '@'}}
   printf("\0"); // expected-warning{{format string contains '\0' within the string body}}
   printf("xs\0"); // expected-warning{{format string contains '\0' within the string body}}

Modified: cfe/trunk/test/SemaObjC/format-strings-objc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/format-strings-objc.m?rev=97318&r1=97317&r2=97318&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/format-strings-objc.m (original)
+++ cfe/trunk/test/SemaObjC/format-strings-objc.m Sat Feb 27 02:34:51 2010
@@ -50,3 +50,8 @@
   printf("%i ",test); // expected-warning{{conversion specifies type 'int' but the argument has type 'long long'}}
   NSLog(@"%i ",test); // expected-warning{{conversion specifies type 'int' but the argument has type 'long long'}}
 }
+
+// <rdar://problem/7697748>
+void rdar_7697748() {
+  NSLog(@"%@!"); // expected-warning{{more '%' conversions than data arguments}}
+}





More information about the cfe-commits mailing list