From 26414ffa0029b93d1320a21e06ffd2b320ef3546 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 17 Mar 2024 22:15:33 +0100 Subject: [PATCH] Fix crash in checkConstPointer() (f'up to #12518) (#6142) --- lib/checkother.cpp | 2 +- test/testother.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index cce598aaf7c..53595c4ad0e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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{}; diff --git a/test/testother.cpp b/test/testother.cpp index b7031723301..8ad022906c3 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {