Skip to content

Commit d92c579

Browse files
Fix #14428 FP duplicateCondition, pointer data may be changed in function call (danmar#8155)
1 parent dc2049b commit d92c579

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/astutils.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,8 +3086,6 @@ static const Token* findExpressionChangedImpl(const Token* expr,
30863086
}
30873087
bool global = false;
30883088
if (tok->variable()) {
3089-
if (tok->variable()->isConst())
3090-
return false;
30913089
global = !tok->variable()->isLocal() && !tok->variable()->isArgument() &&
30923090
!(tok->variable()->isMember() && !tok->variable()->isStatic());
30933091
} else if (tok->isIncompleteVar() && !tok->isIncompleteConstant()) {

test/testcondition.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5899,6 +5899,28 @@ class TestCondition : public TestFixture {
58995899
" if (strlen(s2) > 0) {}\n"
59005900
"}\n");
59015901
ASSERT_EQUALS("", errout_str());
5902+
5903+
check("void g(int*);\n" // #14428
5904+
"int f(int* const p) {\n"
5905+
" int i = 0;\n"
5906+
" if (*p == 0)\n"
5907+
" g(p);\n"
5908+
" if (*p == 0)\n"
5909+
" i = 1;\n"
5910+
" return i;\n"
5911+
"}\n");
5912+
ASSERT_EQUALS("", errout_str());
5913+
5914+
check("void g(const int*);\n"
5915+
"int f(const int* const p) {\n"
5916+
" int i = 0;\n"
5917+
" if (*p == 0)\n"
5918+
" g(p);\n"
5919+
" if (*p == 0)\n"
5920+
" i = 1;\n"
5921+
" return i;\n"
5922+
"}\n");
5923+
ASSERT_EQUALS("[test.cpp:4:12] -> [test.cpp:6:12]: (style) The if condition is the same as the previous if condition [duplicateCondition]\n", errout_str());
59025924
}
59035925

59045926
void checkInvalidTestForOverflow() {

0 commit comments

Comments
 (0)