diff options
Diffstat (limited to 'test/Sema/format-strings.c')
-rw-r--r-- | test/Sema/format-strings.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 6da027e..e31644a 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -1,8 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs %s // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -fno-signed-char %s -#define __need_wint_t #include <stdarg.h> +#include <stddef.h> +#define __need_wint_t #include <stddef.h> // For wint_t and wchar_t typedef struct _FILE FILE; @@ -535,6 +536,21 @@ void pr9751() { 0.0); // expected-warning{{format specifies}} } +void pr18905() { + const char s1[] = "s\0%s"; // expected-note{{format string is defined here}} + const char s2[1] = "s"; // expected-note{{format string is defined here}} + const char s3[2] = "s\0%s"; // expected-warning{{initializer-string for char array is too long}} + const char s4[10] = "s"; + const char s5[0] = "%s"; // expected-warning{{initializer-string for char array is too long}} + // expected-note@-1{{format string is defined here}} + + printf(s1); // expected-warning{{format string contains '\0' within the string body}} + printf(s2); // expected-warning{{format string is not null-terminated}} + printf(s3); // no-warning + printf(s4); // no-warning + printf(s5); // expected-warning{{format string is not null-terminated}} +} + void __attribute__((format(strfmon,1,2))) monformat(const char *fmt, ...); void __attribute__((format(strftime,1,0))) dateformat(const char *fmt); @@ -544,7 +560,7 @@ void test_other_formats() { monformat("", 1); // expected-warning{{format string is empty}} monformat(str); // expected-warning{{format string is not a string literal (potentially insecure)}} dateformat(""); // expected-warning{{format string is empty}} - dateformat(str); // no-warning (using strftime non literal is not unsafe) + dateformat(str); // no-warning (using strftime non-literal is not unsafe) } // Do not warn about unused arguments coming from system headers. |