]> granicus.if.org Git - clang/commitdiff
When checking printf-arguments for functions with '__attribute__ ((format (printf...
authorTed Kremenek <kremenek@apple.com>
Fri, 27 Feb 2009 17:58:43 +0000 (17:58 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 27 Feb 2009 17:58:43 +0000 (17:58 +0000)
set HasVAListArg to true when 'Y' is 0 (i.e., ignore the data arguments).

This fixes <rdar://problem/6623513>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65642 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/format-attribute.c

index 3e6bd5a2efb2f4b96d8803b3a11c7adee11c2af8..b0d6901953f6245cbe3624e341c20b716eb52db4 100644 (file)
@@ -143,12 +143,14 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) {
   // Printf checking.
   if (const FormatAttr *Format = FDecl->getAttr<FormatAttr>()) {
     if (Format->getType() == "printf") {
-      bool HasVAListArg = false;
-      if (const FunctionProtoType *Proto 
-          = FDecl->getType()->getAsFunctionProtoType())
+      bool HasVAListArg = Format->getFirstArg() == 0;
+      if (!HasVAListArg) {
+        if (const FunctionProtoType *Proto 
+            = FDecl->getType()->getAsFunctionProtoType())
         HasVAListArg = !Proto->isVariadic();
+      }
       CheckPrintfArguments(TheCall, HasVAListArg, Format->getFormatIdx() - 1,
-                           Format->getFirstArg() - 1);
+                           HasVAListArg ? 0 : Format->getFirstArg() - 1);
     }
   }
 
index ecdef9dde1a3714b3bee86691c7c4d8e0473bfd3..a1cd0b84b3769f47e13abb3bdfe2c94a66262cb6 100644 (file)
@@ -24,3 +24,11 @@ struct _mystruct {
 };
 
 typedef int (*f3_ptr)(char*,...) __attribute__((format(printf,1,0))); // no-error
+
+// <rdar://problem/6623513>
+int rdar6623513(void *, const char*, const char*, ...)
+  __attribute__ ((format (printf, 3, 0)));
+
+int rdar6623513_aux(int len, const char* s) {
+  rdar6623513(0, "hello", "%.*s", len, s);
+}