aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/GRExprEngineInternalChecks.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-12-08 22:47:34 +0000
committerTed Kremenek <kremenek@apple.com>2008-12-08 22:47:34 +0000
commitefd5994d6a35b6b16b29cc59a0d9ef8a14d9c6f8 (patch)
treebbf326d826d9a0c5a66651080a5820a685d85557 /lib/Analysis/GRExprEngineInternalChecks.cpp
parent26b58cd65f5ae7b90d786b472a0ba527b14637e3 (diff)
Add checking for zero-sized VLAs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60726 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/GRExprEngineInternalChecks.cpp')
-rw-r--r--lib/Analysis/GRExprEngineInternalChecks.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/Analysis/GRExprEngineInternalChecks.cpp b/lib/Analysis/GRExprEngineInternalChecks.cpp
index be7282314d..8b484ab10c 100644
--- a/lib/Analysis/GRExprEngineInternalChecks.cpp
+++ b/lib/Analysis/GRExprEngineInternalChecks.cpp
@@ -163,7 +163,7 @@ public:
"Receiver in message expression is an uninitialized value.") {}
virtual void EmitBuiltinWarnings(BugReporter& BR, GRExprEngine& Eng) {
- for (GRExprEngine::UndefReceiversTy::iterator I=Eng.undef_receivers_begin(),
+ for (GRExprEngine::ErrorNodes::iterator I=Eng.undef_receivers_begin(),
End = Eng.undef_receivers_end(); I!=End; ++I) {
// Generate a report for this bug.
@@ -331,6 +331,33 @@ public:
Emit(BR, Eng.explicit_oob_memacc_begin(), Eng.explicit_oob_memacc_end());
}
};
+
+class VISIBILITY_HIDDEN ZeroSizeVLA : public BuiltinBug {
+
+public:
+ ZeroSizeVLA() : BuiltinBug("Zero-sized VLA",
+ "VLAs with zero-size are undefined.") {}
+
+ virtual void EmitBuiltinWarnings(BugReporter& BR, GRExprEngine& Eng) {
+ for (GRExprEngine::ErrorNodes::iterator
+ I = Eng.ExplicitZeroSizedVLA.begin(),
+ E = Eng.ExplicitZeroSizedVLA.end(); I!=E; ++I) {
+
+ // Generate a report for this bug.
+ PostStmt PS = cast<PostStmt>((*I)->getLocation());
+ DeclStmt *DS = cast<DeclStmt>(PS.getStmt());
+ VarDecl* VD = cast<VarDecl>(*DS->decl_begin());
+ QualType T = Eng.getContext().getCanonicalType(VD->getType());
+ VariableArrayType* VT = cast<VariableArrayType>(T);
+
+ RangedBugReport report(*this, *I);
+ report.addRange(VT->getSizeExpr()->getSourceRange());
+
+ // Emit the warning.
+ BR.EmitWarning(report);
+ }
+ }
+};
//===----------------------------------------------------------------------===//
// __attribute__(nonnull) checking
@@ -403,5 +430,6 @@ void GRExprEngine::RegisterInternalChecks() {
Register(new BadMsgExprArg());
Register(new BadReceiver());
Register(new OutOfBoundMemoryAccess());
+ Register(new ZeroSizeVLA());
AddCheck(new CheckAttrNonNull(), Stmt::CallExprClass);
}