]> granicus.if.org Git - clang/commitdiff
Add format string checking of 'double' arguments. Fixes <rdar://problem/6931734>.
authorTed Kremenek <kremenek@apple.com>
Sat, 30 Jan 2010 01:02:18 +0000 (01:02 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 30 Jan 2010 01:02:18 +0000 (01:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94867 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/PrintfFormatString.cpp
test/Sema/format-strings.c

index 357080fa7439e5e378127521abf898a4b9cadf9d..05b5d9cceba30f9c1b2f75f269373eadaf6c4db6 100644 (file)
@@ -309,6 +309,9 @@ ArgTypeResult FormatSpecifier::getArgType(ASTContext &Ctx) const {
         // version of ptrdiff_t?
         return ArgTypeResult();
     }
+  
+  if (CS.isDoubleArg())
+    return Ctx.DoubleTy;
 
   // FIXME: Handle other cases.
   return ArgTypeResult();
index f1ab868dc72c33b0963e480ec74a945d82d34bfe..21d7770e12cfb4ef322721d26b462657d355d5fa 100644 (file)
@@ -160,6 +160,7 @@ void test10(int x, float f, int i) {
   printf("%"); // expected-warning{{incomplete format specifier}}
   printf("%.d", x); // no-warning
   printf("%.", x);  // expected-warning{{incomplete format specifier}}
+  printf("%f", 4); // expected-warning{{conversion specifies type 'double' but the argument has type 'int'}}
 } 
 
 typedef struct __aslclient *aslclient;