30class ObjCContainersChecker :
public Checker< check::PreStmt<CallExpr>,
31 check::PostStmt<CallExpr>,
32 check::PointerEscape> {
33 mutable std::unique_ptr<BugType> BT;
34 inline void initBugType()
const {
36 BT.reset(
new BugType(
this,
"CFArray API",
46 void addSizeInfo(
const Expr *Array,
const Expr *Size,
58 const char *NL,
const char *Sep)
const override;
65void ObjCContainersChecker::addSizeInfo(
const Expr *Array,
const Expr *Size,
68 SVal SizeV =
C.getSVal(Size);
83void ObjCContainersChecker::checkPostStmt(
const CallExpr *CE,
85 StringRef Name =
C.getCalleeName(CE);
90 if (Name.equals(
"CFArrayCreate")) {
96 addSizeInfo(CE, CE->
getArg(2),
C);
100 if (Name.equals(
"CFArrayGetCount")) {
101 addSizeInfo(CE->
getArg(0), CE,
C);
106void ObjCContainersChecker::checkPreStmt(
const CallExpr *CE,
108 StringRef Name =
C.getCalleeName(CE);
113 if (Name.equals(
"CFArrayGetValueAtIndex")) {
119 SymbolRef ArraySym = getArraySym(ArrayExpr,
C);
130 SVal IdxVal =
C.getSVal(IdxExpr);
138 std::tie(StInBound, StOutBound) = State->assumeInBoundDual(Idx, *Size, T);
139 if (StOutBound && !StInBound) {
144 auto R = std::make_unique<PathSensitiveBugReport>(
145 *BT,
"Index is out of bounds", N);
148 {bugreporter::TrackingKind::Thorough,
150 C.emitReport(std::move(R));
161 for (
const auto &Sym : Escaped) {
167 State = State->remove<ArraySizeMap>(Sym);
172void ObjCContainersChecker::printState(raw_ostream &OS,
ProgramStateRef State,
173 const char *NL,
const char *Sep)
const {
174 ArraySizeMapTy Map = State->get<ArraySizeMap>();
178 OS << Sep <<
"ObjC container sizes :" << NL;
180 OS << I.first <<
" : " << I.second << NL;
189bool ento::shouldRegisterObjCContainersChecker(
const CheckerManager &mgr) {
#define REGISTER_MAP_WITH_PROGRAMSTATE(Name, Key, Value)
Declares an immutable map of type NameTy, suitable for placement into the ProgramState.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
This represents one expression.
A (possibly-)qualified type.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Represents an abstract call to a function or method along a particular path.
virtual void printState(raw_ostream &Out, ProgramStateRef State, const char *NL, const char *Sep) const
See CheckerManager::runCheckersForPrintState.
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
bool isUnknownOrUndef() const
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
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 CoreFoundationObjectiveC
PointerEscapeKind
Describes the different reasons a pointer escapes during analysis.