From 6230a8e49d04d2c9a62e597a14b6417e517bce31 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Mon, 24 Feb 2025 18:48:58 +0100 Subject: [PATCH 1/2] Fix #13654 FP containerOutOfBounds for array size given as product --- lib/valueflow.cpp | 2 +- test/testvalueflow.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 9f5254b02c7..d681899ad32 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6528,7 +6528,7 @@ static void valueFlowContainerSize(const TokenList& tokenlist, const Dimension& dim = var->dimensions().front(); if (dim.known) { size = dim.num; - } else if (dim.tok && dim.tok->hasKnownIntValue()) { + } else if (dim.tok && dim.tok->hasKnownIntValue() && dim.tok->strAt(1) == ">") { size = dim.tok->values().front().intvalue; } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index acc64f1f97d..2539902d130 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7158,6 +7158,12 @@ class TestValueFlow : public TestFixture { " return v[2];\n" "}"; ASSERT(isKnownContainerSizeValue(tokenValues(code, "v ["), 3).empty()); + + code = "auto f() {\n" // #13450 + " std::array a{};\n" + " return a[0];\n" + "}"; + ASSERT(!isKnownContainerSizeValue(tokenValues(code, "a ["), 6).empty()); } void valueFlowContainerElement() From 29c933dfa9b08c07f92d6f5ff8ccd7826696cd23 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Mon, 24 Feb 2025 18:49:55 +0100 Subject: [PATCH 2/2] Comment --- test/testvalueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 2539902d130..5dfd062262e 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7159,7 +7159,7 @@ class TestValueFlow : public TestFixture { "}"; ASSERT(isKnownContainerSizeValue(tokenValues(code, "v ["), 3).empty()); - code = "auto f() {\n" // #13450 + code = "auto f() {\n" // #13654 " std::array a{};\n" " return a[0];\n" "}";