format-strings-scanf.c revision baa400654bd6f8396f9a07188445ae7955b060a3
1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s 286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregortypedef __typeof(sizeof(int)) size_t; 486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregortypedef struct _FILE FILE; 5b0fd483ad64865cc0233981cfddc36a7c9795e5eDouglas Gregor 686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregorint fscanf(FILE * restrict, const char * restrict, ...) ; 786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregorint scanf(const char * restrict, ...) ; 886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregorint sscanf(const char * restrict, const char * restrict, ...) ; 986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 1086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregorvoid test(const char *s, int *i) { 1186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor scanf(s, i); // expected-warning{{ormat string is not a string literal}} 1286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor scanf("%0d", i); // expected-warning{{zero field width in scanf format string is unused}} 1386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor scanf("%00d", i); // expected-warning{{zero field width in scanf format string is unused}} 14b0fd483ad64865cc0233981cfddc36a7c9795e5eDouglas Gregor scanf("%d%[asdfasdfd", i, s); // expected-warning{{no closing ']' for '%[' in scanf format string}} 15b0fd483ad64865cc0233981cfddc36a7c9795e5eDouglas Gregor 1676f7d287020a0b4996d6e9d3968d5bd9a39f7d84Douglas Gregor unsigned short s_x; 1776f7d287020a0b4996d6e9d3968d5bd9a39f7d84Douglas Gregor scanf ("%" "hu" "\n", &s_x); // no-warning 1886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor scanf("%y", i); // expected-warning{{invalid conversion specifier 'y'}} 1986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor scanf("%%"); // no-warning 2086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor scanf("%%%1$d", i); // no-warning 2186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor scanf("%1$d%%", i); // no-warning 2286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor scanf("%d", i, i); // expected-warning{{data argument not used by format string}} 23214f31a347d7824eb92e6a3f5dce4d4047fd5ae0Douglas Gregor scanf("%*d", i); // // expected-warning{{data argument not used by format string}} 24214f31a347d7824eb92e6a3f5dce4d4047fd5ae0Douglas Gregor scanf("%*d", i); // // expected-warning{{data argument not used by format string}} 25214f31a347d7824eb92e6a3f5dce4d4047fd5ae0Douglas Gregor scanf("%*d%1$d", i); // no-warning 26214f31a347d7824eb92e6a3f5dce4d4047fd5ae0Douglas Gregor} 27214f31a347d7824eb92e6a3f5dce4d4047fd5ae0Douglas Gregor