diff options
author | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-02-21 20:00:53 +0000 |
---|---|---|
committer | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-02-21 20:00:53 +0000 |
commit | f57c413e444b441fa75ae8911d183c19b53bdd56 (patch) | |
tree | 8242e39f4ac230f2c3348e89f45d48354439df33 /test/Sema/format-strings.c | |
parent | f4b7de1cef3007cc0479775638198287384d9af1 (diff) |
When calling a non variadic format function(vprintf, vscanf, NSLogv, …), warn if the format string argument is a parameter that is not itself declared as a format string with compatible format.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151080 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/format-strings.c')
-rw-r--r-- | test/Sema/format-strings.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index e6ce6e3c4a..55b8201fd3 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -14,6 +14,8 @@ int vprintf(const char *restrict, va_list); int vsnprintf(char *, size_t, const char *, va_list); int vsprintf(char *restrict, const char *restrict, va_list); // expected-note{{passing argument to parameter here}} +int vscanf(const char *restrict format, va_list arg); + char * global_fmt; void check_string_literal( FILE* fp, const char* s, char *buf, ... ) { @@ -23,21 +25,23 @@ 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}} - vprintf(s,ap); // // no-warning + vprintf(s,ap); // expected-warning {{format string is not a string literal}} fprintf(fp,s); // expected-warning {{format string is not a string literal}} - vfprintf(fp,s,ap); // no-warning + 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}} - vasprintf(&b,s,ap); // no-warning + 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}} snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} __builtin___sprintf_chk(buf,0,-1,s); // expected-warning {{format string is not a string literal}} __builtin___snprintf_chk(buf,2,0,-1,s); // expected-warning {{format string is not a string lit}} - vsprintf(buf,s,ap); // no-warning - vsnprintf(buf,2,s,ap); // no-warning + 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}} - __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // no-warning + __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // expected-warning {{format string is not a string lit}} __builtin___vsnprintf_chk(buf,2,0,-1,global_fmt,ap); // expected-warning {{format string is not a string literal}} + vscanf(s, ap); // expected-warning {{format string is not a string literal}} + // rdar://6079877 printf("abc" "%*d", 1, 1); // no-warning @@ -51,6 +55,25 @@ def" printf("%*d", (unsigned) 1, 1); // no-warning } +__attribute__((__format__ (__printf__, 2, 4))) +void check_string_literal2( FILE* fp, const char* s, char *buf, ... ) { + char * b; + va_list ap; + va_start(ap,buf); + + printf(s); // expected-warning {{format string is not a string literal}} + vprintf(s,ap); // no-warning + fprintf(fp,s); // expected-warning {{format string is not a string literal}} + vfprintf(fp,s,ap); // no-warning + asprintf(&b,s); // expected-warning {{format string is not a string lit}} + vasprintf(&b,s,ap); // no-warning + sprintf(buf,s); // expected-warning {{format string is not a string literal}} + snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} + __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // no-warning + + vscanf(s, ap); // expected-warning {{format string is not a string literal}} +} + 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 |