25class UndefinedNewArraySizeChecker :
public Checker<check::PreCall> {
28 BugType BT{
this,
"Undefined array element count in new[]",
39void UndefinedNewArraySizeChecker::checkPreCall(
const CallEvent &
Call,
41 if (
const auto *AC = dyn_cast<CXXAllocatorCall>(&
Call)) {
45 auto *SizeEx = *AC->getArraySizeExpr();
46 auto SizeVal = AC->getArraySizeVal();
48 if (SizeVal.isUndef())
49 HandleUndefinedArrayElementCount(
C, SizeVal, SizeEx,
50 SizeEx->getSourceRange());
54void UndefinedNewArraySizeChecker::HandleUndefinedArrayElementCount(
60 llvm::raw_svector_ostream os(buf);
62 os <<
"Element count in new[] is a garbage value";
64 auto R = std::make_unique<PathSensitiveBugReport>(BT, os.str(), N);
65 R->markInteresting(ArgVal);
69 C.emitReport(std::move(R));
73void ento::registerUndefinedNewArraySizeChecker(
CheckerManager &mgr) {
77bool ento::shouldRegisterUndefinedNewArraySizeChecker(
This represents one expression.
A trivial tuple used to represent a source range.
Represents an abstract call to a function or method along a particular path.
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
const LangOptions & getLangOpts() const
A Range represents the closed range [from, to].
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
bool trackExpressionValue(const ExplodedNode *N, const Expr *E, PathSensitiveBugReport &R, TrackingOptions Opts={})
Attempts to add visitors to track expression value back to its point of origin.
const char *const LogicError
The JSON file list parser is used to communicate input to InstallAPI.