aboutsummaryrefslogtreecommitdiff
path: root/test/Sema/format-strings.c
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-01-30 00:49:51 +0000
committerTed Kremenek <kremenek@apple.com>2010-01-30 00:49:51 +0000
commitd635c5fcc45c952b75743dd2f4c86d6950e4954e (patch)
tree29dacdd5dcf27bf7e16b51272e597c0e0ba68336 /test/Sema/format-strings.c
parent31f8e32788adb299acad455363eb7fd244642c82 (diff)
Add basic type checking of format string conversion specifiers and their arguments. Thanks to Cristian Draghici for his help with this patch!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94864 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/format-strings.c')
-rw-r--r--test/Sema/format-strings.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c
index 94fb593730..f1ab868dc7 100644
--- a/test/Sema/format-strings.c
+++ b/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'}}
+}