From 87ac6b336ef0c58585b920ab44120fa94f28e730 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:12:28 +0200 Subject: [PATCH 1/2] Update astutils.cpp --- lib/astutils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 9506c5bba30..8e6ee974f15 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -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; From ce27e4a4797b5d4d66785a7ee04daeb6289cff24 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:13:47 +0200 Subject: [PATCH 2/2] Update testcondition.cpp --- test/testcondition.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 42fa09ef010..caafd5a0bc2 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -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() {