Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,8 @@ static const Token * followVariableExpression(const Settings& settings, const To
const Token * lastTok = precedes(tok, end) ? end : tok;
// If this is in a loop then check if variables are modified in the entire scope
const Token * endToken = (isInLoopCondition(tok) || isInLoopCondition(varTok) || var->scope() != tok->scope()) ? var->scope()->bodyEnd : lastTok;
if (!var->isConst() && (!precedes(varTok, endToken) || isVariableChanged(varTok, endToken, tok->varId(), false, settings)))
const int indirect = var->isArray() ? var->dimensions().size() : 0;
if (!var->isConst() && (!precedes(varTok, endToken) || isVariableChanged(varTok, endToken, indirect, tok->varId(), false, settings)))
return tok;
if (precedes(varTok, endToken) && isAliased(varTok, endToken, tok->varId()))
return tok;
Expand Down
13 changes: 13 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5849,6 +5849,19 @@ class TestCondition : public TestFixture {
" if (f < 10.0) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("void f(char* s, const char* p) {\n" // #14070
" strcpy(s, p);\n"
"}\n"
"void g() {\n"
" char s1[10] = \"\";\n"
" char s2[10] = \"\";\n"
" f(s1, \"123\");\n"
" f(s2, \"1234\");\n"
" if (strlen(s1) > 0) {}\n"
" if (strlen(s2) > 0) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void checkInvalidTestForOverflow() {
Expand Down
Loading