Skip to content

Commit

Permalink
[analyzer][NFCi] Use the correct BugType in CStringChecker.
Browse files Browse the repository at this point in the history
There is different bug types for different types of bugs  but the **emitAdditionOverflowbug** seems to use bugtype **BT_NotCSting** but actually it have to use **BT_AdditionOverflow** .

Reviewed By: steakhal

Differential Revision: https://reviews.llvm.org/D119462
  • Loading branch information
phyBrackets committed Feb 14, 2022
1 parent f037082 commit 6745b6a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
Expand Up @@ -257,7 +257,6 @@ class CStringChecker : public Checker< eval::Call,
void emitNotCStringBug(CheckerContext &C, ProgramStateRef State,
const Stmt *S, StringRef WarningMsg) const;
void emitAdditionOverflowBug(CheckerContext &C, ProgramStateRef State) const;

ProgramStateRef checkAdditionOverflow(CheckerContext &C,
ProgramStateRef state,
NonLoc left,
Expand Down Expand Up @@ -420,7 +419,6 @@ ProgramStateRef CStringChecker::CheckBufferAccess(CheckerContext &C,

SVal BufEnd =
svalBuilder.evalBinOpLN(State, BO_Add, *BufLoc, LastOffset, PtrTy);

State = CheckLocation(C, State, Buffer, BufEnd, Access);

// If the buffer isn't large enough, abort.
Expand Down Expand Up @@ -622,8 +620,8 @@ void CStringChecker::emitNotCStringBug(CheckerContext &C, ProgramStateRef State,
void CStringChecker::emitAdditionOverflowBug(CheckerContext &C,
ProgramStateRef State) const {
if (ExplodedNode *N = C.generateErrorNode(State)) {
if (!BT_NotCString)
BT_NotCString.reset(
if (!BT_AdditionOverflow)
BT_AdditionOverflow.reset(
new BuiltinBug(Filter.CheckNameCStringOutOfBounds, "API",
"Sum of expressions causes overflow."));

Expand All @@ -634,8 +632,8 @@ void CStringChecker::emitAdditionOverflowBug(CheckerContext &C,
"This expression will create a string whose length is too big to "
"be represented as a size_t";

auto Report =
std::make_unique<PathSensitiveBugReport>(*BT_NotCString, WarningMsg, N);
auto Report = std::make_unique<PathSensitiveBugReport>(*BT_AdditionOverflow,
WarningMsg, N);
C.emitReport(std::move(Report));
}
}
Expand Down

0 comments on commit 6745b6a

Please sign in to comment.