diff options
author | Bob Wilson <bob.wilson@apple.com> | 2016-03-15 20:56:38 +0000 |
---|---|---|
committer | Bob Wilson <bob.wilson@apple.com> | 2016-03-15 20:56:38 +0000 |
commit | 57819fc809d1a72e253233930bbd06f13fb9bae6 (patch) | |
tree | 732cab7e54e904040185c40282a3aea9b90d21b0 /clang/test/Sema/format-strings.c | |
parent | 20c1e4e69d05e56d270e8380679c8735bac2c6d2 (diff) | |
download | bcm5719-llvm-57819fc809d1a72e253233930bbd06f13fb9bae6.tar.gz bcm5719-llvm-57819fc809d1a72e253233930bbd06f13fb9bae6.zip |
Move the fixit for -Wformat-security to a note.
r263299 added a fixit for the -Wformat-security warning, but that runs
into complications with our guideline that error recovery should be done
as-if the fixit had been applied. Putting the fixit on a note avoids that.
llvm-svn: 263584
Diffstat (limited to 'clang/test/Sema/format-strings.c')
-rw-r--r-- | clang/test/Sema/format-strings.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c index 69723f6e1ac..5559710c603 100644 --- a/clang/test/Sema/format-strings.c +++ b/clang/test/Sema/format-strings.c @@ -29,15 +29,22 @@ void check_string_literal( FILE* fp, const char* s, char *buf, ... ) { va_start(ap,buf); printf(s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} vprintf(s,ap); // expected-warning {{format string is not a string literal}} fprintf(fp,s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} vfprintf(fp,s,ap); // expected-warning {{format string is not a string literal}} asprintf(&b,s); // expected-warning {{format string is not a string lit}} + // expected-note@-1{{treat the string as an argument to avoid this}} vasprintf(&b,s,ap); // expected-warning {{format string is not a string literal}} sprintf(buf,s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} + // expected-note@-1{{treat the string as an argument to avoid this}} __builtin___sprintf_chk(buf,0,-1,s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} __builtin___snprintf_chk(buf,2,0,-1,s); // expected-warning {{format string is not a string lit}} + // expected-note@-1{{treat the string as an argument to avoid this}} vsprintf(buf,s,ap); // expected-warning {{format string is not a string lit}} vsnprintf(buf,2,s,ap); // expected-warning {{format string is not a string lit}} vsnprintf(buf,2,global_fmt,ap); // expected-warning {{format string is not a string literal}} @@ -72,13 +79,18 @@ void check_string_literal2( FILE* fp, const char* s, char *buf, ... ) { va_start(ap,buf); printf(s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} vprintf(s,ap); // no-warning fprintf(fp,s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} vfprintf(fp,s,ap); // no-warning asprintf(&b,s); // expected-warning {{format string is not a string lit}} + // expected-note@-1{{treat the string as an argument to avoid this}} vasprintf(&b,s,ap); // no-warning sprintf(buf,s); // expected-warning {{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} + // expected-note@-1{{treat the string as an argument to avoid this}} __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // no-warning vscanf(s, ap); // expected-warning {{format string is not a string literal}} @@ -88,6 +100,7 @@ void check_conditional_literal(const char* s, int i) { printf(i == 1 ? "yes" : "no"); // no-warning printf(i == 0 ? (i == 1 ? "yes" : "no") : "dont know"); // no-warning printf(i == 0 ? (i == 1 ? s : "no") : "dont know"); // expected-warning{{format string is not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} printf("yes" ?: "no %d", 1); // expected-warning{{data argument not used by format string}} printf(0 ? "yes %s" : "no %d", 1); // no-warning printf(0 ? "yes %d" : "no %s", 1); // expected-warning{{format specifies type 'char *'}} @@ -202,8 +215,11 @@ void test_constant_bindings(void) { printf(s1); // no-warning printf(s2); // no-warning printf(s3); // expected-warning{{not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} printf(s4); // expected-warning{{not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} printf(s5); // expected-warning{{not a string literal}} + // expected-note@-1{{treat the string as an argument to avoid this}} } @@ -214,6 +230,7 @@ void test_constant_bindings(void) { void test9(char *P) { int x; printf(P); // expected-warning {{format string is not a string literal (potentially insecure)}} + // expected-note@-1{{treat the string as an argument to avoid this}} printf(P, 42); } @@ -632,5 +649,6 @@ extern void test_format_security_extra_args(const char*, int, ...) __attribute__((__format__(__printf__, 1, 3))); void test_format_security_pos(char* string) { test_format_security_extra_args(string, 5); // expected-warning {{format string is not a string literal (potentially insecure)}} + // expected-note@-1{{treat the string as an argument to avoid this}} } #pragma GCC diagnostic warning "-Wformat-nonliteral" |