From 63151f3291cc75b40fa7166156015309946cb5c2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 9 Apr 2023 16:38:09 +0200 Subject: [PATCH] Fix crash in constPointer() (#4945) --- lib/checkother.cpp | 2 +- test/testother.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 31c29d4e4..f99751eab 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1478,7 +1478,7 @@ void CheckOther::checkConstVariable() else opTok = opTok->astOperand2(); } - if (opTok->valueType() && var->valueType() && opTok->valueType()->isConst(var->valueType()->pointer)) + if (opTok && opTok->valueType() && var->valueType() && opTok->valueType()->isConst(var->valueType()->pointer)) continue; } else if (const Token* ftok = getTokenArgumentFunction(tok, argn)) { bool inconclusive{}; diff --git a/test/testother.cpp b/test/testother.cpp index 7388329da..43a398a0b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3486,6 +3486,12 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); // don't crash + check("void f(int& i) {\n" + " int& r = i;\n" + " if (!&r) {}\n" + "}\n"); + TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'r' can be declared as reference to const\n", "", errout.str()); // don't crash + check("class C;\n" // #11646 "void g(const C* const p);\n" "void f(C* c) {\n"