Skip to content

Commit 817013f

Browse files
Fix #14070 FP duplicateCondition for modified string (#7737)
1 parent 9dd0555 commit 817013f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/astutils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,8 @@ static const Token * followVariableExpression(const Settings& settings, const To
12121212
const Token * lastTok = precedes(tok, end) ? end : tok;
12131213
// If this is in a loop then check if variables are modified in the entire scope
12141214
const Token * endToken = (isInLoopCondition(tok) || isInLoopCondition(varTok) || var->scope() != tok->scope()) ? var->scope()->bodyEnd : lastTok;
1215-
if (!var->isConst() && (!precedes(varTok, endToken) || isVariableChanged(varTok, endToken, tok->varId(), false, settings)))
1215+
const int indirect = var->isArray() ? var->dimensions().size() : 0;
1216+
if (!var->isConst() && (!precedes(varTok, endToken) || isVariableChanged(varTok, endToken, indirect, tok->varId(), false, settings)))
12161217
return tok;
12171218
if (precedes(varTok, endToken) && isAliased(varTok, endToken, tok->varId()))
12181219
return tok;

test/testcondition.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5849,6 +5849,19 @@ class TestCondition : public TestFixture {
58495849
" if (f < 10.0) {}\n"
58505850
"}\n");
58515851
ASSERT_EQUALS("", errout_str());
5852+
5853+
check("void f(char* s, const char* p) {\n" // #14070
5854+
" strcpy(s, p);\n"
5855+
"}\n"
5856+
"void g() {\n"
5857+
" char s1[10] = \"\";\n"
5858+
" char s2[10] = \"\";\n"
5859+
" f(s1, \"123\");\n"
5860+
" f(s2, \"1234\");\n"
5861+
" if (strlen(s1) > 0) {}\n"
5862+
" if (strlen(s2) > 0) {}\n"
5863+
"}\n");
5864+
ASSERT_EQUALS("", errout_str());
58525865
}
58535866

58545867
void checkInvalidTestForOverflow() {

0 commit comments

Comments
 (0)