diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-01-30 00:49:51 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-01-30 00:49:51 +0000 |
commit | c3bdff7c8c9c0faa49cf0fc7683ff977ca3a1df9 (patch) | |
tree | a7047ce7b1bb33f1ccc6e557ccecc87271cbfb5a /clang/test/Sema/format-strings.c | |
parent | 4b71b6c179620c222e935390ac6b1baf9649b908 (diff) | |
download | bcm5719-llvm-c3bdff7c8c9c0faa49cf0fc7683ff977ca3a1df9.tar.gz bcm5719-llvm-c3bdff7c8c9c0faa49cf0fc7683ff977ca3a1df9.zip |
Add basic type checking of format string conversion specifiers and their arguments. Thanks to Cristian Draghici for his help with this patch!
llvm-svn: 94864
Diffstat (limited to 'clang/test/Sema/format-strings.c')
-rw-r--r-- | clang/test/Sema/format-strings.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c index 94fb5937301..f1ab868dc72 100644 --- a/clang/test/Sema/format-strings.c +++ b/clang/test/Sema/format-strings.c @@ -71,8 +71,8 @@ void check_invalid_specifier(FILE* fp, char *buf) { printf("%s%lb%d","unix",10,20); // expected-warning {{invalid conversion specifier 'b'}} fprintf(fp,"%%%l"); // expected-warning {{incomplete format specifier}} - sprintf(buf,"%%%%%ld%d%d", 1, 2, 3); // no-warning - snprintf(buf, 2, "%%%%%ld%;%d", 1, 2, 3); // expected-warning {{invalid conversion specifier ';'}} + sprintf(buf,"%%%%%ld%d%d", 1, 2, 3); // expected-warning{{conversion specifies type 'long' but the argument has type 'int'}} + snprintf(buf, 2, "%%%%%ld%;%d", 1, 2, 3); // expected-warning{{conversion specifies type 'long' but the argument has type 'int'}} expected-warning {{invalid conversion specifier ';'}} } void check_null_char_string(char* b) @@ -162,3 +162,11 @@ void test10(int x, float f, int i) { printf("%.", x); // expected-warning{{incomplete format specifier}} } +typedef struct __aslclient *aslclient; +typedef struct __aslmsg *aslmsg; +int asl_log(aslclient asl, aslmsg msg, int level, const char *format, ...) __attribute__((__format__ (__printf__, 4, 5))); +void test_asl(aslclient asl) { + // Test case from <rdar://problem/7341605>. + asl_log(asl, 0, 3, "Error: %m"); // no-warning + asl_log(asl, 0, 3, "Error: %W"); // expected-warning{{invalid conversion specifier 'W'}} +} |