diff options
author | Hans Wennborg <hans@hanshq.net> | 2011-12-10 13:20:11 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2011-12-10 13:20:11 +0000 |
commit | b1a5e09f6fda84cd1b4af43fa4a85547bf2c2c56 (patch) | |
tree | bfb864b39e601d7ac5c827fd81e381d411711f81 /clang/test/Sema/format-strings-scanf.c | |
parent | 29dad49cfd3fe31596b5e574578e2c9383100d4b (diff) | |
download | bcm5719-llvm-b1a5e09f6fda84cd1b4af43fa4a85547bf2c2c56.tar.gz bcm5719-llvm-b1a5e09f6fda84cd1b4af43fa4a85547bf2c2c56.zip |
Check that arguments to a scanf call match the format specifier,
and offer fixits when there is a mismatch.
llvm-svn: 146326
Diffstat (limited to 'clang/test/Sema/format-strings-scanf.c')
-rw-r--r-- | clang/test/Sema/format-strings-scanf.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/clang/test/Sema/format-strings-scanf.c b/clang/test/Sema/format-strings-scanf.c index ee559daef61..467586215b2 100644 --- a/clang/test/Sema/format-strings-scanf.c +++ b/clang/test/Sema/format-strings-scanf.c @@ -28,7 +28,7 @@ void test(const char *s, int *i) { void bad_length_modifiers(char *s, void *p, wchar_t *ws, long double *ld) { scanf("%hhs", "foo"); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 's' conversion specifier}} - scanf("%1$zp", p); // expected-warning{{length modifier 'z' results in undefined behavior or no effect with 'p' conversion specifier}} + scanf("%1$zp", &p); // expected-warning{{length modifier 'z' results in undefined behavior or no effect with 'p' conversion specifier}} scanf("%ls", ws); // no-warning scanf("%#.2Lf", ld); // expected-warning{{invalid conversion specifier '#'}} } @@ -37,10 +37,11 @@ void bad_length_modifiers(char *s, void *p, wchar_t *ws, long double *ld) { // format string is somewhere else, point to it in a note. void pr9751() { int *i; + char str[100]; const char kFormat1[] = "%00d"; // expected-note{{format string is defined here}}} scanf(kFormat1, i); // expected-warning{{zero field width in scanf format string is unused}} scanf("%00d", i); // expected-warning{{zero field width in scanf format string is unused}} const char kFormat2[] = "%["; // expected-note{{format string is defined here}}} - scanf(kFormat2, &i); // expected-warning{{no closing ']' for '%[' in scanf format string}} - scanf("%[", &i); // expected-warning{{no closing ']' for '%[' in scanf format string}} + scanf(kFormat2, str); // expected-warning{{no closing ']' for '%[' in scanf format string}} + scanf("%[", str); // expected-warning{{no closing ']' for '%[' in scanf format string}} } |