Skip to content

Commit 440e510

Browse files
authored
[clang][analyzer] Fix a nullptr dereference when -ftime-trace is used (#139820)
Fixes #139779. The bug was introduced in #137355 in `SymbolConjured::getStmt`, when trying to obtain a statement for a CFG initializer without an initializer. This commit adds a null check before access.
1 parent 7e690db commit 440e510

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ class SymbolConjured : public SymbolData {
103103
const Stmt *getStmt() const {
104104
switch (Elem->getKind()) {
105105
case CFGElement::Initializer:
106-
return Elem->castAs<CFGInitializer>().getInitializer()->getInit();
106+
if (const auto *Init = Elem->castAs<CFGInitializer>().getInitializer()) {
107+
return Init->getInit();
108+
}
109+
return nullptr;
107110
case CFGElement::ScopeBegin:
108111
return Elem->castAs<CFGScopeBegin>().getTriggerStmt();
109112
case CFGElement::ScopeEnd:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,apiModeling %s -ftime-trace=%t.raw.json -verify
2+
// expected-no-diagnostics
3+
4+
// GitHub issue 139779
5+
struct {} a; // no-crash

0 commit comments

Comments
 (0)