]> granicus.if.org Git - clang/commitdiff
Fix crasher caused by setting a bit in a possibly empty bitvector while
authorTed Kremenek <kremenek@apple.com>
Sat, 27 Feb 2010 08:34:51 +0000 (08:34 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 27 Feb 2010 08:34:51 +0000 (08:34 +0000)
doing printf format string checking.  This is a recent regression.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97318 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/format-strings.c
test/SemaObjC/format-strings-objc.m

index 7198dad53397938153ee384641c9dfa3893fb37f..c7b9cb7b9befaa66c4a0da5113b971afc761e7ec 100644 (file)
@@ -1283,7 +1283,12 @@ CheckPrintfHandler::HandleFormatSpecifier(const analyze_printf::FormatSpecifier
 
   // 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.
index e92e17da084c3099a3557175ca90de1c969c25fe..21d3aec840f641b2a974eadab624620c7dbedbc1 100644 (file)
@@ -145,6 +145,7 @@ void torture(va_list v8) {
 }
 
 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}}
index 7abfe9622358cb821212f83a290cba6bd6a01ae7..1fcc34f695d80eb621a4704bf9bde68d3543410e 100644 (file)
@@ -50,3 +50,8 @@ void rdar_7068334() {
   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}}
+}