From 1e40a2e73e391f3c15c53242018d11756b4ef996 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 3 May 2022 20:15:42 +0200 Subject: [PATCH] Fix #5210 C-style pointer casting not detected for casts to ** (#4075) --- lib/checkother.cpp | 2 +- test/testother.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 7c542dc53..fccd25ca4 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -301,7 +301,7 @@ void CheckOther::warningOldStylePointerCast() tok = scope->bodyStart; for (; tok && tok != scope->bodyEnd; tok = tok->next()) { // Old style pointer casting.. - if (!Token::Match(tok, "( const|volatile| const|volatile|class|struct| %type% * const|&| ) (| %name%|%num%|%bool%|%char%|%str%")) + if (!Token::Match(tok, "( const|volatile| const|volatile|class|struct| %type% * *| *| const|&| ) (| %name%|%num%|%bool%|%char%|%str%")) continue; if (Token::Match(tok->previous(), "%type%")) continue; diff --git a/test/testother.cpp b/test/testother.cpp index 8a0d2e766..c946fa7c8 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1567,6 +1567,15 @@ private: " auto h = reinterpret_cast(p);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #5210 + checkOldStylePointerCast("void f(void* v1, void* v2) {\n" + " T** p1 = (T**)v1;\n" + " T*** p2 = (T***)v2;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (style) C-style pointer casting\n" + "[test.cpp:3]: (style) C-style pointer casting\n", + errout.str()); } #define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__)