Skip to content

Commit

Permalink
Fix crash in checkConstPointer() (f'up to #12518) (#6142)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Mar 17, 2024
1 parent 967323e commit 26414ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,7 @@ void CheckOther::checkConstPointer()
continue;
else if (gparent && gparent->isCast() && gparent->valueType() &&
((gparent->valueType()->pointer == 0 && gparent->valueType()->reference == Reference::None) ||
(var->valueType() && parent->valueType()->isConst(var->valueType()->pointer))))
(var->valueType() && gparent->valueType()->isConst(var->valueType()->pointer))))
continue;
else if (const Token* ftok = getTokenArgumentFunction(parent, argn)) {
bool inconclusive{};
Expand Down
8 changes: 8 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4097,6 +4097,14 @@ class TestOther : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'src' can be declared as pointer to const\n",
errout_str());

check("struct S {};\n"
"void f(T* t) {\n"
" S* s = (S*)t->p;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) C-style pointer casting\n"
"[test.cpp:3]: (style) Variable 's' can be declared as pointer to const\n",
errout_str()); // don't crash
}

void switchRedundantAssignmentTest() {
Expand Down

0 comments on commit 26414ff

Please sign in to comment.