From f6cdafb3616f3a6d8e2fffbfe5f1e07bd5ff04c1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 31 Aug 2026 17:02:17 +0200 Subject: [PATCH 1/5] Update valueflow.cpp --- lib/valueflow.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 325a55e98e5..aa0b2c91c29 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5422,6 +5422,11 @@ static void valueFlowForLoopSimplifyAfter(Token* fortok, nonneg int varid, const endToken = fortok->scope()->bodyEnd; Token* blockTok = fortok->linkAt(1)->linkAt(1); + if (const Token* escape = findEscapeStatement(blockTok->scope(), settings.library)) { + if (settings.debugwarnings) + bailout(tokenlist, errorLogger, escape, "For loop variable bailout on escape statement"); + return; + } if (blockTok != endToken) { ValueFlow::Value v{num}; v.errorPath.emplace_back(fortok,"After for loop, " + var->name() + " has value " + v.infoString()); From a69e457e9993bdb677e7a600a6b86209ecedee27 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 31 Aug 2026 17:03:04 +0200 Subject: [PATCH 2/5] Update testtokenize.cpp --- test/testtokenize.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index cc793f58873..c0f8ec97827 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -1323,6 +1323,10 @@ class TestTokenizer : public TestFixture { "return ; } }\n\n" "return ;\n" "}", tokenizeAndStringify(code)); + ASSERT_EQUALS( + "[test.cpp:5:1]: (debug) valueflow.cpp:5426:valueFlowForLoopSimplifyAfter bailout: For loop variable bailout on escape statement [valueFlowBailout]\n" + "[test.cpp:5:1]: (debug) valueflow.cpp:5426:valueFlowForLoopSimplifyAfter bailout: For loop variable bailout on escape statement [valueFlowBailout]\n", + errout_str()); } void ifAddBraces7() { From 4513b60428c9c1bfec5a92fa7330a7b190ea3d1e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 31 Aug 2026 17:04:02 +0200 Subject: [PATCH 3/5] Update testvalueflow.cpp --- test/testvalueflow.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 56bd0e26ce2..54d80f458f6 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5143,6 +5143,18 @@ class TestValueFlow : public TestFixture { ++it; ASSERT_EQUALS(5, it->intvalue); ASSERT(it->isImpossible()); + + code = "int a[5];\n" // #14998 + "int f() {\n" + " int i;\n" + " for (i = 0; true; ++i) {\n" + " if (i == 4)\n" + " break;\n" + " }\n" + " return a[i];\n" + "}\n"; + values = tokenValues(code, "i ]"); + ASSERT(values.empty()); } void valueFlowSubFunction() { From fe8c2df0a3b1fe9d07d11368a422e8b96ac25bc2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 31 Aug 2026 17:22:21 +0200 Subject: [PATCH 4/5] Update testtokenize.cpp --- test/testtokenize.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c0f8ec97827..94a64b54640 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -1324,8 +1324,8 @@ class TestTokenizer : public TestFixture { "return ;\n" "}", tokenizeAndStringify(code)); ASSERT_EQUALS( - "[test.cpp:5:1]: (debug) valueflow.cpp:5426:valueFlowForLoopSimplifyAfter bailout: For loop variable bailout on escape statement [valueFlowBailout]\n" - "[test.cpp:5:1]: (debug) valueflow.cpp:5426:valueFlowForLoopSimplifyAfter bailout: For loop variable bailout on escape statement [valueFlowBailout]\n", + "[test.cpp:5:1]: (debug) valueflow.cpp:5427:valueFlowForLoopSimplifyAfter bailout: For loop variable bailout on escape statement [valueFlowBailout]\n" + "[test.cpp:5:1]: (debug) valueflow.cpp:5427:valueFlowForLoopSimplifyAfter bailout: For loop variable bailout on escape statement [valueFlowBailout]\n", errout_str()); } From 8ad15b7dbdbccb83af3fc289999e5b96c2a94595 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 1 Sep 2026 08:25:48 +0200 Subject: [PATCH 5/5] Update testtokenize.cpp --- test/testtokenize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 94a64b54640..e9399d62a30 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -1323,7 +1323,7 @@ class TestTokenizer : public TestFixture { "return ; } }\n\n" "return ;\n" "}", tokenizeAndStringify(code)); - ASSERT_EQUALS( + ASSERT_EQUALS_WITHOUT_LINENUMBERS( "[test.cpp:5:1]: (debug) valueflow.cpp:5427:valueFlowForLoopSimplifyAfter bailout: For loop variable bailout on escape statement [valueFlowBailout]\n" "[test.cpp:5:1]: (debug) valueflow.cpp:5427:valueFlowForLoopSimplifyAfter bailout: For loop variable bailout on escape statement [valueFlowBailout]\n", errout_str());