From cec9ce49dcf4b4b768043f96c8ef8c1d4cdbb6b9 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Mon, 30 Jul 2012 17:11:32 +0000 Subject: Make -Wformat check the argument type for %n. This makes Clang check that the corresponding argument for "%n" in a format string is a pointer to int. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160966 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ScanfFormatString.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/Analysis/ScanfFormatString.cpp') diff --git a/lib/Analysis/ScanfFormatString.cpp b/lib/Analysis/ScanfFormatString.cpp index 5c7e6ef8f2..3c848f1f09 100644 --- a/lib/Analysis/ScanfFormatString.cpp +++ b/lib/Analysis/ScanfFormatString.cpp @@ -303,6 +303,9 @@ ScanfArgTypeResult ScanfSpecifier::getArgType(ASTContext &Ctx) const { case ConversionSpecifier::pArg: return ScanfArgTypeResult(ArgTypeResult(ArgTypeResult::CPointerTy)); + case ConversionSpecifier::nArg: + return ArgTypeResult(Ctx.IntTy); + default: break; } @@ -315,6 +318,10 @@ bool ScanfSpecifier::fixType(QualType QT, const LangOptions &LangOpt, if (!QT->isPointerType()) return false; + // %n is different from other conversion specifiers; don't try to fix it. + if (CS.getKind() == ConversionSpecifier::nArg) + return false; + QualType PT = QT->getPointeeType(); // If it's an enum, get its underlying type. -- cgit v1.2.3