summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/format-strings.c
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-12-17 19:03:13 +0000
committerTed Kremenek <kremenek@apple.com>2007-12-17 19:03:13 +0000
commit3fbeaea7eef240cd5131aec8465d4fbf57658df7 (patch)
treea1a0bb5408dcc9f92637d719bcc9d03eacef63bf /clang/test/Sema/format-strings.c
parentd39b8c0269f5472d1ca967c27229105755808095 (diff)
downloadbcm5719-llvm-3fbeaea7eef240cd5131aec8465d4fbf57658df7.tar.gz
bcm5719-llvm-3fbeaea7eef240cd5131aec8465d4fbf57658df7.zip
Modified format-string checking to not emit a warning when all of the
following hold: (1) A vprintf-like function is called that takes the argument list via a via_list argument. (2) The format string is a non-literal that is the parameter value of the enclosing function, e.g: void logmessage(const char *fmt,...) { va_list ap; va_start(ap,fmt); fprintf(fmt,ap); // Do not emit a warning. } In the future this special case will be enhanced to consult the "format" attribute attached to a function declaration instead of just allowing a blank check for all function parameters to be used as format strings to vprintf-like functions. This will happen when more support for attributes becomes available. llvm-svn: 45114
Diffstat (limited to 'clang/test/Sema/format-strings.c')
-rw-r--r--clang/test/Sema/format-strings.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c
index e5bbd70bfde..c1e690a3b80 100644
--- a/clang/test/Sema/format-strings.c
+++ b/clang/test/Sema/format-strings.c
@@ -3,6 +3,8 @@
#include <stdio.h>
#include <stdarg.h>
+char * global_fmt;
+
void check_string_literal( FILE* fp, const char* s, char *buf, ... ) {
char * b;
@@ -10,15 +12,16 @@ 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); // expected-warning {{format string is not a string liter}}
+ vprintf(s,ap); // // no-warning
fprintf(fp,s); // expected-warning {{format string is not a string literal}}
- vfprintf(fp,s,ap); // expected-warning {{format string is not a string lit}}
+ vfprintf(fp,s,ap); // no-warning
asprintf(&b,s); // expected-warning {{format string is not a string lit}}
- vasprintf(&b,s,ap); // 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}}
- vsprintf(buf,s,ap); // expected-warning {{format string is not a string lit}}
- vsnprintf(buf,2,s,ap); // expected-warning {{mat string is not a string lit}}
+ vsprintf(buf,s,ap); // no-warning
+ vsnprintf(buf,2,s,ap); // no-warning
+ vsnprintf(buf,2,global_fmt,ap); // expected-warning {{format string is not a string literal}}
}
void check_writeback_specifier()
OpenPOWER on IntegriCloud