Skip to content

Commit

Permalink
Fix #12185 FN constVariablePointer with stream (#5659)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Nov 16, 2023
1 parent e01e090 commit 831aec5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ void CheckOther::checkConstPointer()
}
} else {
int argn = -1;
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-"))
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-|<<"))
continue;
if (Token::simpleMatch(parent, "(") && Token::Match(parent->astOperand1(), "if|while"))
continue;
Expand Down
2 changes: 1 addition & 1 deletion test/cfg/opencv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void ignoredReturnValue()

void memleak()
{
char * pBuf = (char *)cv::fastMalloc(1000); // cppcheck-suppress cstyleCast
const char * pBuf = (char *)cv::fastMalloc(1000); // cppcheck-suppress cstyleCast
std::cout << pBuf;
// cppcheck-suppress memleak
}
9 changes: 8 additions & 1 deletion test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3882,6 +3882,13 @@ class TestOther : public TestFixture {
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'r' can be declared as pointer to const\n"
"[test.cpp:1]: (style) Parameter 'b' can be declared as pointer to const\n",
errout.str());

check("void f(int i) {\n" // #12185
" void* p = &i;\n"
" std::cout << p << '\\n';\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n",
errout.str());
}

void switchRedundantAssignmentTest() {
Expand Down Expand Up @@ -8436,7 +8443,7 @@ class TestOther : public TestFixture {
" ptr = otherPtr;\n"
" free(otherPtr - xx - 1);\n"
"}");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'ptr' can be declared as pointer to const\n", errout.str());
}

void checkRedundantCopy() {
Expand Down

0 comments on commit 831aec5

Please sign in to comment.