diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-03-25 03:59:12 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-03-25 03:59:12 +0000 |
commit | 6ee765348b2855c702fa593fb030ef6abe0d01f6 (patch) | |
tree | 050fc89d24e82d40bed63ee34005f57580699d31 /test/Sema/format-strings.c | |
parent | fdb703ab3a3c28aeb53b3db4c54e14a30d78dc4e (diff) |
Fix two bugs in format-string checking:
(1) Do not assume the data arguments start after the format string
(2) Do not use the fact that a function is variadic to treat it like a va_list printf function
Fixes PR 6697.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99480 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/format-strings.c')
-rw-r--r-- | test/Sema/format-strings.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 4db775f96c..dcc4c35d01 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -238,3 +238,16 @@ void test_positional_arguments() { printf("%2$*8$d", (int) 2, (int) 3); // expected-warning{{specified field width is missing a matching 'int' argument}} } +// PR 6697 - Handle format strings where the data argument is not adjacent to the format string +void myprintf_PR_6697(const char *format, int x, ...) __attribute__((__format__(printf,1, 3))); +void test_pr_6697() { + myprintf_PR_6697("%s\n", 1, "foo"); // no-warning + myprintf_PR_6697("%s\n", 1, (int)0); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}} + // FIXME: Not everything should clearly support positional arguments, + // but we need a way to identify those cases. + myprintf_PR_6697("%1$s\n", 1, "foo"); // no-warning + myprintf_PR_6697("%2$s\n", 1, "foo"); // expected-warning{{data argument position '2' exceeds the number of data arguments (1)}} + myprintf_PR_6697("%18$s\n", 1, "foo"); // expected-warning{{data argument position '18' exceeds the number of data arguments (1)}} + myprintf_PR_6697("%1$s\n", 1, (int) 0); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}} +} + |