diff options
author | dim <dim@FreeBSD.org> | 2010-09-17 15:54:40 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2010-09-17 15:54:40 +0000 |
commit | 36c49e3f258dced101949edabd72e9bc3f1dedc4 (patch) | |
tree | 0bbe07708f7571f8b5291f6d7b96c102b7c99dee /test/Sema/format-strings-scanf.c | |
parent | fc84956ac8b7cd244ef30e7a4d4d38a58dec5904 (diff) | |
download | FreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.zip FreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.tar.gz |
Vendor import of clang r114020 (from the release_28 branch):
http://llvm.org/svn/llvm-project/cfe/branches/release_28@114020
Approved by: rpaulo (mentor)
Diffstat (limited to 'test/Sema/format-strings-scanf.c')
-rw-r--r-- | test/Sema/format-strings-scanf.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/Sema/format-strings-scanf.c b/test/Sema/format-strings-scanf.c new file mode 100644 index 0000000..42b6c03 --- /dev/null +++ b/test/Sema/format-strings-scanf.c @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s + +typedef __typeof(sizeof(int)) size_t; +typedef struct _FILE FILE; +typedef __WCHAR_TYPE__ wchar_t; + +int fscanf(FILE * restrict, const char * restrict, ...) ; +int scanf(const char * restrict, ...) ; +int sscanf(const char * restrict, const char * restrict, ...) ; + +void test(const char *s, int *i) { + scanf(s, i); // expected-warning{{ormat string is not a string literal}} + scanf("%0d", 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}} + scanf("%d%[asdfasdfd", i, s); // expected-warning{{no closing ']' for '%[' in scanf format string}} + + unsigned short s_x; + scanf ("%" "hu" "\n", &s_x); // no-warning + scanf("%y", i); // expected-warning{{invalid conversion specifier 'y'}} + scanf("%%"); // no-warning + scanf("%%%1$d", i); // no-warning + scanf("%1$d%%", i); // no-warning + scanf("%d", i, i); // expected-warning{{data argument not used by format string}} + scanf("%*d", i); // // expected-warning{{data argument not used by format string}} + scanf("%*d", i); // // expected-warning{{data argument not used by format string}} + scanf("%*d%1$d", i); // no-warning +} + +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("%ls", ws); // no-warning + scanf("%#.2Lf", ld); // expected-warning{{invalid conversion specifier '#'}} +} |