Skip to content

Commit d172b65

Browse files
nectoTomasz Kamiński
authored andcommitted
[analyzer] Fix crash in MoveChecker when it tries to report duplicate issue
The 'MoveChecker' was missing the check if the error node was successfully generated (non-null value was returned). This happens if duplicate of the report is emitted. This patch contains NFC, where 'reportBug' is renamed to 'tryReportBug', to better indicate conditional behavior of function. Author: Arseniy Zaostrovnykh <arseniy.zaostrovnykh@sonarsource.com> Reviewed By: xazax.hun Differential Revision: https://reviews.llvm.org/D155084
1 parent 405889e commit d172b65

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ class MoveChecker
213213

214214
// Returns the exploded node against which the report was emitted.
215215
// The caller *must* add any further transitions against this node.
216-
ExplodedNode *reportBug(const MemRegion *Region, const CXXRecordDecl *RD,
217-
CheckerContext &C, MisuseKind MK) const;
216+
// Returns nullptr and does not report if such node already exists.
217+
ExplodedNode *tryToReportBug(const MemRegion *Region, const CXXRecordDecl *RD,
218+
CheckerContext &C, MisuseKind MK) const;
218219

219220
bool isInMoveSafeContext(const LocationContext *LC) const;
220221
bool isStateResetMethod(const CXXMethodDecl *MethodDec) const;
@@ -377,19 +378,20 @@ void MoveChecker::modelUse(ProgramStateRef State, const MemRegion *Region,
377378
return;
378379
}
379380

380-
ExplodedNode *N = reportBug(Region, RD, C, MK);
381+
ExplodedNode *N = tryToReportBug(Region, RD, C, MK);
381382

382383
// If the program has already crashed on this path, don't bother.
383-
if (N->isSink())
384+
if (!N || N->isSink())
384385
return;
385386

386387
State = State->set<TrackedRegionMap>(Region, RegionState::getReported());
387388
C.addTransition(State, N);
388389
}
389390

390-
ExplodedNode *MoveChecker::reportBug(const MemRegion *Region,
391-
const CXXRecordDecl *RD, CheckerContext &C,
392-
MisuseKind MK) const {
391+
ExplodedNode *MoveChecker::tryToReportBug(const MemRegion *Region,
392+
const CXXRecordDecl *RD,
393+
CheckerContext &C,
394+
MisuseKind MK) const {
393395
if (ExplodedNode *N = misuseCausesCrash(MK) ? C.generateErrorNode()
394396
: C.generateNonFatalErrorNode()) {
395397
// Uniqueing report to the same object.

0 commit comments

Comments
 (0)