clang 24.0.0git
CStringChecker.cpp File Reference

Go to the source code of this file.

Macros

#define REGISTER_CHECKER(NAME)

Typedefs

using SearchFn
 Resolve the haystack and delegate to a function-specific search lambda.

Functions

static std::optional< NonLocgetIndex (ProgramStateRef State, const ElementRegion *ER, CharKind CK)
static void printIdxWithOrdinalSuffix (llvm::raw_ostream &Os, unsigned Idx)
static std::optional< StringRef > getHaystack (CheckerContext &C, const CallEvent &Call)
 Compute the constant search offset for strchr/strrchr/strchrnul.
static StringRef getCStr (StringRef Haystack)
 Get the null-terminated C string view of the haystack.
static std::optional< char > getSearchChar (CheckerContext &C, const CallEvent &Call)
 Try to extract the constant character from the second argument.
static std::optional< size_tcomputeStringOffset (CheckerContext &C, const CallEvent &Call, SearchFn Search)
static std::optional< size_tsearchChar (CheckerContext &C, const CallEvent &Call, StringRef Haystack, bool Reverse, bool NulOnMiss)
 Search for a character in the null-terminated C string view.

Macro Definition Documentation

◆ REGISTER_CHECKER

#define REGISTER_CHECKER ( NAME)
Value:
void ento::registerCString##NAME(CheckerManager &Mgr) { \
Mgr.getChecker<CStringChecker>()->NAME.enable(Mgr); \
} \
\
bool ento::shouldRegisterCString##NAME(const CheckerManager &) { \
return true; \
}
CHECKER * getChecker(AT &&...Args)
If the the singleton instance of a checker class is not yet constructed, then construct it (with the ...

Definition at line 3253 of file CStringChecker.cpp.

Typedef Documentation

◆ SearchFn

using SearchFn
Initial value:
CheckerContext &, const CallEvent &, StringRef)>
Represents an abstract call to a function or method along a particular path.
Definition CallEvent.h:152
int const char * function
Definition c++config.h:31

Resolve the haystack and delegate to a function-specific search lambda.

Definition at line 2701 of file CStringChecker.cpp.

Function Documentation

◆ computeStringOffset()

std::optional< size_t > computeStringOffset ( CheckerContext & C,
const CallEvent & Call,
SearchFn Search )
static

Definition at line 2705 of file CStringChecker.cpp.

References clang::C, clang::Call, and getHaystack().

◆ getCStr()

StringRef getCStr ( StringRef Haystack)
static

Get the null-terminated C string view of the haystack.

Definition at line 2684 of file CStringChecker.cpp.

Referenced by searchChar().

◆ getHaystack()

std::optional< StringRef > getHaystack ( CheckerContext & C,
const CallEvent & Call )
static

Compute the constant search offset for strchr/strrchr/strchrnul.

Try to resolve the source (first) argument to its string literal content.

Definition at line 2675 of file CStringChecker.cpp.

References clang::C, clang::Call, and clang::ento::SVal::getAsRegion().

Referenced by computeStringOffset().

◆ getIndex()

◆ getSearchChar()

std::optional< char > getSearchChar ( CheckerContext & C,
const CallEvent & Call )
static

Try to extract the constant character from the second argument.

Definition at line 2690 of file CStringChecker.cpp.

References clang::C, clang::Call, and clang::ento::SValBuilder::getKnownValue().

Referenced by searchChar().

◆ printIdxWithOrdinalSuffix()

void printIdxWithOrdinalSuffix ( llvm::raw_ostream & Os,
unsigned Idx )
static

Definition at line 450 of file CStringChecker.cpp.

◆ searchChar()

std::optional< size_t > searchChar ( CheckerContext & C,
const CallEvent & Call,
StringRef Haystack,
bool Reverse,
bool NulOnMiss )
static

Search for a character in the null-terminated C string view.

Definition at line 2714 of file CStringChecker.cpp.

References clang::C, clang::Call, getCStr(), and getSearchChar().