Fix #5210 C-style pointer casting not detected for casts to ** (#4075)

This commit is contained in:
chrchr-github 2022-05-03 20:15:42 +02:00 committed by GitHub
parent 509e42afd4
commit 1e40a2e73e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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;

View File

@ -1567,6 +1567,15 @@ private:
" auto h = reinterpret_cast<void (STDAPICALLTYPE*)(int)>(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__)