diff options
| -rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 7 | ||||
| -rw-r--r-- | clang/test/Sema/format-strings.c | 1 | ||||
| -rw-r--r-- | clang/test/SemaObjC/format-strings-objc.m | 5 |
3 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 7198dad5339..c7b9cb7b9be 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -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. diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c index e92e17da084..21d3aec840f 100644 --- a/clang/test/Sema/format-strings.c +++ b/clang/test/Sema/format-strings.c @@ -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}} diff --git a/clang/test/SemaObjC/format-strings-objc.m b/clang/test/SemaObjC/format-strings-objc.m index 7abfe962235..1fcc34f695d 100644 --- a/clang/test/SemaObjC/format-strings-objc.m +++ b/clang/test/SemaObjC/format-strings-objc.m @@ -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}} +} |

