Skip to content

Commit 44b2b45

Browse files
Fix #14231 Crash in checkConstVariable() (#7931)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 019c37c commit 44b2b45

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ void CheckOther::checkConstVariable()
17231723
if (retTok->varId() == var->declarationId())
17241724
return true;
17251725
while (retTok && retTok->isCast())
1726-
retTok = retTok->astOperand2();
1726+
retTok = retTok->astOperand2() ? retTok->astOperand2() : retTok->astOperand1();
17271727
while (Token::simpleMatch(retTok, "."))
17281728
retTok = retTok->astOperand2();
17291729
if (Token::simpleMatch(retTok, "&"))

test/testother.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3967,6 +3967,13 @@ class TestOther : public TestFixture {
39673967

39683968
check("size_t* f(std::array<uint8_t, 128>& a) { return reinterpret_cast<size_t*>(a.data()); }\n"); // #14074
39693969
ASSERT_EQUALS("", errout_str());
3970+
3971+
check("struct S { int i; };\n" // #14231
3972+
"void* f(S& s, int& v) {\n"
3973+
" v = s.i;\n"
3974+
" return (void*)&s;\n"
3975+
"}\n"); // don't crash
3976+
ASSERT_EQUALS("", errout_str());
39703977
}
39713978

39723979
void constParameterCallback() {

0 commit comments

Comments
 (0)