]> granicus.if.org Git - clang/commitdiff
Fix format string checking of '%c' by treating it as an integer conversion. Fixes...
authorTed Kremenek <kremenek@apple.com>
Thu, 17 Jun 2010 01:12:20 +0000 (01:12 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 17 Jun 2010 01:12:20 +0000 (01:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106196 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/Analyses/PrintfFormatString.h
test/Sema/format-strings-fixit.c
test/Sema/format-strings.c

index 039e5a96e6a5073f557623c5105295f365c7cc29..9aa7d6ff4e826e2bbb02a17f1d9eebc3600c913c 100644 (file)
@@ -57,6 +57,7 @@ public:
    InvalidSpecifier = 0,
     // C99 conversion specifiers.
    dArg, // 'd'
+   IntAsCharArg,  // 'c'
    iArg, // 'i',
    oArg, // 'o',
    uArg, // 'u',
@@ -70,7 +71,6 @@ public:
    GArg, // 'G',
    aArg, // 'a',
    AArg, // 'A',
-   IntAsCharArg,  // 'c'
    CStrArg,       // 's'
    VoidPtrArg,    // 'p'
    OutIntPtrArg,  // 'n'
index bbdd4d81059539e63496f98450d4443ca4ec286c..84f69f059e6bea2b76419215ed49fd1967686240 100644 (file)
@@ -15,6 +15,8 @@ void test() {
   printf("abc%0f", "testing testing 123");
   printf("%u", (long) -12);
   printf("%p", 123);
+  printf("%c\n", "x");
+  printf("%c\n", 1.23);
 
   // Larger types
   printf("%+.2d", (unsigned long long) 123456);
index 72aa5927c3077dae702ff5fc55da409025878106..b3c9cc98ef735293e471862bc455022c0486d4d7 100644 (file)
@@ -172,6 +172,8 @@ 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'}}
   // The man page says that a zero precision is okay.
   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'}}
 } 
 
 void test11(void *p, char *s) {