#include "clang/Basic/TargetInfo.h"
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
usingnamespaceclang;
usingnamespaceento;
enum class OpenVariant { … };
namespace {
class UnixAPIMisuseChecker
: public Checker<check::PreCall, check::ASTDecl<TranslationUnitDecl>> { … };
class UnixAPIPortabilityChecker : public Checker< check::PreStmt<CallExpr> > { … };
}
ProgramStateRef UnixAPIMisuseChecker::EnsurePtrNotNull(
SVal PtrVal, const Expr *PtrExpr, CheckerContext &C, ProgramStateRef State,
const StringRef PtrDescr,
std::optional<std::reference_wrapper<const BugType>> BT) const { … }
void UnixAPIMisuseChecker::checkASTDecl(const TranslationUnitDecl *TU,
AnalysisManager &Mgr,
BugReporter &) const { … }
void UnixAPIMisuseChecker::checkPreCall(const CallEvent &Call,
CheckerContext &C) const { … }
void UnixAPIMisuseChecker::ReportOpenBug(CheckerContext &C,
ProgramStateRef State,
const char *Msg,
SourceRange SR) const { … }
void UnixAPIMisuseChecker::CheckOpen(CheckerContext &C,
const CallEvent &Call) const { … }
void UnixAPIMisuseChecker::CheckOpenAt(CheckerContext &C,
const CallEvent &Call) const { … }
void UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
const CallEvent &Call,
OpenVariant Variant) const { … }
ProgramStateRef UnixAPIMisuseChecker::EnsureGetdelimBufferAndSizeCorrect(
SVal LinePtrPtrSVal, SVal SizePtrSVal, const Expr *LinePtrPtrExpr,
const Expr *SizePtrExpr, CheckerContext &C, ProgramStateRef State) const { … }
void UnixAPIMisuseChecker::CheckGetDelim(CheckerContext &C,
const CallEvent &Call) const { … }
void UnixAPIMisuseChecker::CheckPthreadOnce(CheckerContext &C,
const CallEvent &Call) const { … }
static bool IsZeroByteAllocation(ProgramStateRef state,
const SVal argVal,
ProgramStateRef *trueState,
ProgramStateRef *falseState) { … }
bool UnixAPIPortabilityChecker::ReportZeroByteAllocation(
CheckerContext &C,
ProgramStateRef falseState,
const Expr *arg,
const char *fn_name) const { … }
void UnixAPIPortabilityChecker::BasicAllocationCheck(CheckerContext &C,
const CallExpr *CE,
const unsigned numArgs,
const unsigned sizeArg,
const char *fn) const { … }
void UnixAPIPortabilityChecker::CheckCallocZero(CheckerContext &C,
const CallExpr *CE) const { … }
void UnixAPIPortabilityChecker::CheckMallocZero(CheckerContext &C,
const CallExpr *CE) const { … }
void UnixAPIPortabilityChecker::CheckReallocZero(CheckerContext &C,
const CallExpr *CE) const { … }
void UnixAPIPortabilityChecker::CheckReallocfZero(CheckerContext &C,
const CallExpr *CE) const { … }
void UnixAPIPortabilityChecker::CheckAllocaZero(CheckerContext &C,
const CallExpr *CE) const { … }
void UnixAPIPortabilityChecker::CheckAllocaWithAlignZero(
CheckerContext &C,
const CallExpr *CE) const { … }
void UnixAPIPortabilityChecker::CheckVallocZero(CheckerContext &C,
const CallExpr *CE) const { … }
void UnixAPIPortabilityChecker::checkPreStmt(const CallExpr *CE,
CheckerContext &C) const { … }
#define REGISTER_CHECKER(CHECKERNAME) …
REGISTER_CHECKER(UnixAPIMisuseChecker)
REGISTER_CHECKER(UnixAPIPortabilityChecker)