#include "NotNullTerminatedResultCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
#include <optional>
usingnamespaceclang::ast_matchers;
namespace clang::tidy::bugprone {
constexpr llvm::StringLiteral FunctionExprName = …;
constexpr llvm::StringLiteral CastExprName = …;
constexpr llvm::StringLiteral UnknownDestName = …;
constexpr llvm::StringLiteral DestArrayTyName = …;
constexpr llvm::StringLiteral DestVarDeclName = …;
constexpr llvm::StringLiteral DestMallocExprName = …;
constexpr llvm::StringLiteral DestExprName = …;
constexpr llvm::StringLiteral SrcVarDeclName = …;
constexpr llvm::StringLiteral SrcExprName = …;
constexpr llvm::StringLiteral LengthExprName = …;
constexpr llvm::StringLiteral WrongLengthExprName = …;
constexpr llvm::StringLiteral UnknownLengthName = …;
enum class LengthHandleKind { … };
namespace {
static Preprocessor *PP;
}
static const Expr *getDestCapacityExpr(const MatchFinder::MatchResult &Result) { … }
static unsigned getLength(const Expr *E,
const MatchFinder::MatchResult &Result) { … }
static int getDestCapacity(const MatchFinder::MatchResult &Result) { … }
static const CallExpr *getStrlenExpr(const MatchFinder::MatchResult &Result) { … }
static int getGivenLength(const MatchFinder::MatchResult &Result) { … }
static StringRef exprToStr(const Expr *E,
const MatchFinder::MatchResult &Result) { … }
static SourceLocation exprLocEnd(const Expr *E,
const MatchFinder::MatchResult &Result) { … }
static bool isInjectUL(const MatchFinder::MatchResult &Result) { … }
static bool isKnownDest(const MatchFinder::MatchResult &Result) { … }
static bool isDestBasedOnGivenLength(const MatchFinder::MatchResult &Result) { … }
static bool isDestAndSrcEquals(const MatchFinder::MatchResult &Result) { … }
static bool isStringDataAndLength(const MatchFinder::MatchResult &Result) { … }
static bool
isGivenLengthEqualToSrcLength(const MatchFinder::MatchResult &Result) { … }
static bool isCorrectGivenLength(const MatchFinder::MatchResult &Result) { … }
static bool isDestCapacityOverflows(const MatchFinder::MatchResult &Result) { … }
static bool
isFixedGivenLengthAndUnknownSrc(const MatchFinder::MatchResult &Result) { … }
static void lengthExprHandle(const Expr *LengthExpr,
LengthHandleKind LengthHandle,
const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
static void lengthArgHandle(LengthHandleKind LengthHandle,
const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
static void lengthArgPosHandle(unsigned ArgPos, LengthHandleKind LengthHandle,
const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
static bool isDestExprFix(const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
static bool isDestCapacityFix(const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
static void removeArg(int ArgPos, const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
static void renameFunc(StringRef NewFuncName,
const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
static void renameMemcpy(StringRef Name, bool IsCopy, bool IsSafe,
const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
static void insertDestCapacityArg(bool IsOverflows, StringRef Name,
const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
static void insertNullTerminatorExpr(StringRef Name,
const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
NotNullTerminatedResultCheck::NotNullTerminatedResultCheck(
StringRef Name, ClangTidyContext *Context)
: … { … }
void NotNullTerminatedResultCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) { … }
void NotNullTerminatedResultCheck::registerPPCallbacks(
const SourceManager &SM, Preprocessor *Pp, Preprocessor *ModuleExpanderPP) { … }
namespace {
AST_MATCHER_P(Expr, hasDefinition, ast_matchers::internal::Matcher<Expr>,
InnerMatcher) { … }
}
void NotNullTerminatedResultCheck::registerMatchers(MatchFinder *Finder) { … }
void NotNullTerminatedResultCheck::check(
const MatchFinder::MatchResult &Result) { … }
void NotNullTerminatedResultCheck::memoryHandlerFunctionFix(
StringRef Name, const MatchFinder::MatchResult &Result) { … }
void NotNullTerminatedResultCheck::memcpyFix(
StringRef Name, const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
void NotNullTerminatedResultCheck::memcpy_sFix(
StringRef Name, const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) { … }
void NotNullTerminatedResultCheck::memchrFix(
StringRef Name, const MatchFinder::MatchResult &Result) { … }
void NotNullTerminatedResultCheck::memmoveFix(
StringRef Name, const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) const { … }
void NotNullTerminatedResultCheck::strerror_sFix(
const MatchFinder::MatchResult &Result) { … }
void NotNullTerminatedResultCheck::ncmpFix(
StringRef Name, const MatchFinder::MatchResult &Result) { … }
void NotNullTerminatedResultCheck::xfrmFix(
StringRef Name, const MatchFinder::MatchResult &Result) { … }
}