summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/ScanfFormatString.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2012-07-30 17:11:32 +0000
committerHans Wennborg <hans@hanshq.net>2012-07-30 17:11:32 +0000
commitebcd1c7ca2e21192dee17985221c7c0efb017506 (patch)
treed668bcf284ccf52aea6f3652021602f0dd1e16fd /clang/lib/Analysis/ScanfFormatString.cpp
parentdfe14f7848d2389c9c02d74b2f8e732832e00ffa (diff)
downloadbcm5719-llvm-ebcd1c7ca2e21192dee17985221c7c0efb017506.tar.gz
bcm5719-llvm-ebcd1c7ca2e21192dee17985221c7c0efb017506.zip
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. llvm-svn: 160966
Diffstat (limited to 'clang/lib/Analysis/ScanfFormatString.cpp')
-rw-r--r--clang/lib/Analysis/ScanfFormatString.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/Analysis/ScanfFormatString.cpp b/clang/lib/Analysis/ScanfFormatString.cpp
index 5c7e6ef8f27..3c848f1f093 100644
--- a/clang/lib/Analysis/ScanfFormatString.cpp
+++ b/clang/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.
OpenPOWER on IntegriCloud