From: Ted Kremenek Date: Fri, 27 Feb 2009 17:58:43 +0000 (+0000) Subject: When checking printf-arguments for functions with '__attribute__ ((format (printf... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d692df4b9c58895f9843b03543ec57447c93679;p=clang When checking printf-arguments for functions with '__attribute__ ((format (printf, X, Y)))' set HasVAListArg to true when 'Y' is 0 (i.e., ignore the data arguments). This fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65642 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 3e6bd5a2ef..b0d6901953 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -143,12 +143,14 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) { // Printf checking. if (const FormatAttr *Format = FDecl->getAttr()) { 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); } } diff --git a/test/Sema/format-attribute.c b/test/Sema/format-attribute.c index ecdef9dde1..a1cd0b84b3 100644 --- a/test/Sema/format-attribute.c +++ b/test/Sema/format-attribute.c @@ -24,3 +24,11 @@ struct _mystruct { }; typedef int (*f3_ptr)(char*,...) __attribute__((format(printf,1,0))); // no-error + +// +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); +}