25class StringChecker :
public Checker<check::PreCall> {
27 mutable const FunctionDecl *StringConstCharPtrCtor =
nullptr;
29 const CallDescription TwoParamStdStringCtor = {
30 CDM::CXXMethod, {
"std",
"basic_string",
"basic_string"}, 2, 2};
32 bool isCharToStringCtor(
const CallEvent &
Call,
const ASTContext &ACtx)
const;
35 void checkPreCall(
const CallEvent &
Call, CheckerContext &
C)
const;
42 const auto *FD = dyn_cast<FunctionDecl>(
Call.getDecl());
46 if (StringConstCharPtrCtor && StringConstCharPtrCtor == FD)
52 const QualType Arg1Ty =
Call.getArgExpr(0)->getType().getCanonicalType();
53 const QualType Arg2Ty =
Call.getArgExpr(1)->getType().getCanonicalType();
63 StringConstCharPtrCtor = FD;
67void StringChecker::checkPreCall(
const CallEvent &
Call,
68 CheckerContext &
C)
const {
69 if (!isCharToStringCtor(
Call,
C.getASTContext()))
71 const auto Param =
Call.getArgSVal(0).getAs<Loc>();
77 std::tie(NotNull, Null) =
C.getState()->assume(*Param);
80 const auto Callback = [Param](PathSensitiveBugReport &BR) -> std::string {
81 return BR.isInteresting(*Param) ?
"Assuming the pointer is not null."
86 C.addTransition(NotNull, Null ?
C.getNoteTag(Callback) :
nullptr);
91 if (ExplodedNode *N =
C.generateErrorNode(
C.getState())) {
92 auto R = std::make_unique<PathSensitiveBugReport>(
93 BT_Null,
"The parameter must not be null", N);
95 C.emitReport(std::move(R));
101void ento::registerStringChecker(CheckerManager &Mgr) {
105bool ento::shouldRegisterStringChecker(
const CheckerManager &) {
return true; }
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
QualType getCanonicalType() const
bool isPointerType() const
bool matches(const CallEvent &Call) const
Returns true if the CallEvent is a call to a function that matches the CallDescription.
Represents an abstract call to a function or method along a particular path.
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
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
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
bool Null(InterpState &S, CodePtr OpPC, uint64_t Value, const Descriptor *Desc)
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.