aboutsummaryrefslogtreecommitdiff
path: root/test/Sema/format-strings.c
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-02-11 09:27:41 +0000
committerTed Kremenek <kremenek@apple.com>2010-02-11 09:27:41 +0000
commit5c41ee8c49995fb4fd76d686b239c15cbab261ea (patch)
treeb8fc243b142bb4fdd68ee1783c2aa8cd4feb9cdc /test/Sema/format-strings.c
parent824d7ea07a4e9208925daa6ae9289fb2b39bce9f (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95869 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/format-strings.c')
-rw-r--r--test/Sema/format-strings.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c
index 5ce3eb036e..1bbc68cd0d 100644
--- a/test/Sema/format-strings.c
+++ b/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)));