summaryrefslogtreecommitdiffstats
path: root/test/Sema/format-strings.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/Sema/format-strings.c')
-rw-r--r--test/Sema/format-strings.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c
index 2325454..be506d7 100644
--- a/test/Sema/format-strings.c
+++ b/test/Sema/format-strings.c
@@ -174,7 +174,16 @@ void test10(int x, float f, int i, long long lli) {
printf("%.0Lf", (long double) 1.0); // no-warning
printf("%c\n", "x"); // expected-warning{{conversion specifies type 'int' but the argument has type 'char *'}}
printf("%c\n", 1.23); // expected-warning{{conversion specifies type 'int' but the argument has type 'double'}}
-}
+ printf("Format %d, is %! %f", 1, 2, 4.4); // expected-warning{{invalid conversion specifier '!'}}
+}
+
+typedef unsigned char uint8_t;
+
+void should_understand_small_integers() {
+ printf("%hhu", (short) 10); // expected-warning{{conversion specifies type 'unsigned char' but the argument has type 'short'}}
+ printf("%hu\n", (unsigned char) 1); // expected-warning{{conversion specifies type 'unsigned short' but the argument has type 'unsigned char'}}
+ printf("%hu\n", (uint8_t)1); // expected-warning{{conversion specifies type 'unsigned short' but the argument has type 'uint8_t'}}
+}
void test11(void *p, char *s) {
printf("%p", p); // no-warning
@@ -301,3 +310,33 @@ void pr7981(wint_t c, wchar_t c2) {
printf("%lc", c2); // no-warning
}
+// <rdar://problem/8269537> -Wformat-security says NULL is not a string literal
+void rdar8269537() {
+ // This is likely to crash in most cases, but -Wformat-nonliteral technically
+ // doesn't warn in this case.
+ printf(0); // no-warning
+}
+
+// Handle functions with multiple format attributes.
+extern void rdar8332221_vprintf_scanf(const char *, va_list, const char *, ...)
+ __attribute__((__format__(__printf__, 1, 0)))
+ __attribute__((__format__(__scanf__, 3, 4)));
+
+void rdar8332221(va_list ap, int *x, long *y) {
+ rdar8332221_vprintf_scanf("%", ap, "%d", x); // expected-warning{{incomplete format specifier}}
+}
+
+// PR8641
+void pr8641() {
+ printf("%#x\n", 10);
+ printf("%#X\n", 10);
+}
+
+void posix_extensions() {
+ // Test %'d, "thousands grouping".
+ // <rdar://problem/8816343>
+ printf("%'d\n", 123456789); // no-warning
+ printf("%'i\n", 123456789); // no-warning
+ printf("%'f\n", (float) 1.0); // no-warning
+ printf("%'p\n", (void*) 0); // expected-warning{{results in undefined behavior with 'p' conversion specifier}}
+}
OpenPOWER on IntegriCloud