diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-02-11 09:27:41 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-02-11 09:27:41 +0000 |
commit | d31b2637abd2aa6941625a60034cccdab61fe134 (patch) | |
tree | 8b3b58563efefcb97563417e5d2cc3caf64fb728 /clang/test/Sema/format-strings.c | |
parent | fbf1f02fee7c99f7e932852c89f3f871c8cdf4c7 (diff) | |
download | bcm5719-llvm-d31b2637abd2aa6941625a60034cccdab61fe134.tar.gz bcm5719-llvm-d31b2637abd2aa6941625a60034cccdab61fe134.zip |
Patch by Cristian Draghici:
Enhance the printf format string checking when using the format
specifier flags ' ', '0', '+' with the 'p' or 's' conversions (since
they are nonsensical and undefined). This is similar to GCC's
checking.
Also warning when a precision is used with the 'p' conversin
specifier, since it has no meaning.
llvm-svn: 95869
Diffstat (limited to 'clang/test/Sema/format-strings.c')
-rw-r--r-- | clang/test/Sema/format-strings.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c index 5ce3eb036eb..1bbc68cd0d5 100644 --- a/clang/test/Sema/format-strings.c +++ b/clang/test/Sema/format-strings.c @@ -171,6 +171,18 @@ void test10(int x, float f, int i, long long lli) { printf("%f\n", (long double) 1.0); // expected-warning{{conversion specifies type 'double' but the argument has type 'long double'}} } +void test11(void *p, char *s) { + printf("%p", p); // no-warning + printf("%.4p", p); // expected-warning{{precision used in 'p' conversion specifier (where it has no meaning)}} + printf("%+p", p); // expected-warning{{flag '+' results in undefined behavior in 'p' conversion specifier}} + printf("% p", p); // expected-warning{{flag ' ' results in undefined behavior in 'p' conversion specifier}} + printf("%0p", p); // expected-warning{{flag '0' results in undefined behavior in 'p' conversion specifier}} + printf("%s", s); // no-warning + printf("%+s", p); // expected-warning{{flag '+' results in undefined behavior in 's' conversion specifier}} + printf("% s", p); // expected-warning{{flag ' ' results in undefined behavior in 's' conversion specifier}} + printf("%0s", p); // expected-warning{{flag '0' results in undefined behavior in 's' conversion 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))); |