27 using namespace clang;
31 class ObjCContainersChecker :
public Checker< check::PreStmt<CallExpr>,
32 check::PostStmt<CallExpr>,
33 check::PointerEscape> {
34 mutable std::unique_ptr<BugType> BT;
35 inline void initBugType()
const {
37 BT.reset(
new BugType(
this,
"CFArray API",
47 void addSizeInfo(
const Expr *Array,
const Expr *Size,
52 static void *getTag() {
static int Tag;
return &Tag; }
66 void ObjCContainersChecker::addSizeInfo(
const Expr *Array,
const Expr *Size,
84 void ObjCContainersChecker::checkPostStmt(
const CallExpr *CE,
91 if (Name.equals(
"CFArrayCreate")) {
97 addSizeInfo(CE, CE->
getArg(2), C);
101 if (Name.equals(
"CFArrayGetCount")) {
102 addSizeInfo(CE->
getArg(0), CE, C);
107 void ObjCContainersChecker::checkPreStmt(
const CallExpr *CE,
114 if (Name.equals(
"CFArrayGetValueAtIndex")) {
120 SymbolRef ArraySym = getArraySym(ArrayExpr, C);
124 const DefinedSVal *Size = State->get<ArraySizeMap>(ArraySym);
139 ProgramStateRef StOutBound = State->assumeInBound(Idx, *Size,
false, T);
140 if (StOutBound && !StInBound) {
145 auto R = llvm::make_unique<BugReport>(*BT,
"Index is out of bounds", N);
158 for (
const auto &Sym : Escaped) {
164 State = State->remove<ArraySizeMap>(Sym);
const char *const CoreFoundationObjectiveC
A (possibly-)qualified type.
ExplodedNode * generateErrorNode(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generate a transition to a node that will be used to report an error.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
ExplodedNode * addTransition(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generates a new transition in the program state graph (ExplodedGraph).
StringRef getCalleeName(const FunctionDecl *FunDecl) const
Get the name of the called function (path-sensitive).
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
#define REGISTER_MAP_WITH_PROGRAMSTATE(Name, Key, Value)
Declares an immutable map of type NameTy, suitable for placement into the ProgramState.
Expr - This represents one expression.
const FunctionProtoType * T
void emitReport(std::unique_ptr< BugReport > R)
Emit the diagnostics report.
CHECKER * registerChecker()
Used to register checkers.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Dataflow Directional Tag Classes.
Represents an abstract call to a function or method along a particular path.
PointerEscapeKind
Describes the different reasons a pointer escapes during analysis.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
const ProgramStateRef & getState() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
const LocationContext * getLocationContext() const
bool isUnknownOrUndef() const