From 9d4d56444d5663161fec878b326f0cb269a88fa2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 5 Aug 2026 10:10:41 +0200 Subject: [PATCH 1/3] Remove redundant test configuration --- test/testvalueflow.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index c98680b8180..f08f13dccb3 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -43,16 +43,9 @@ class TestValueFlow : public TestFixture { TestValueFlow() : TestFixture("TestValueFlow") {} private: - /*const*/ Settings settings = settingsBuilder().library("std.cfg").build(); + const Settings settings = settingsBuilder().library("std.cfg").build(); void run() override { - // strcpy, abort cfg - constexpr char cfg[] = "\n" - "\n" - " \n" - " true \n" // abort is a noreturn function - ""; - settings = settingsBuilder(settings).libraryxml(cfg).build(); mNewTemplate = true; TEST_CASE(valueFlowNumber); From ea723c2b3a919b232a8bb005b50e435e3c6e0df9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 5 Aug 2026 10:18:11 +0200 Subject: [PATCH 2/3] Update testvalueflow.cpp --- test/testvalueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index f08f13dccb3..954443a8d6e 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -43,7 +43,7 @@ class TestValueFlow : public TestFixture { TestValueFlow() : TestFixture("TestValueFlow") {} private: - const Settings settings = settingsBuilder().library("std.cfg").build(); + /*const*/ Settings settings = settingsBuilder().library("std.cfg").build(); void run() override { From 5443cd44ef2da594bdfb2d6957448f279bee2832 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Wed, 5 Aug 2026 18:55:26 +0200 Subject: [PATCH 3/3] const --- test/testvalueflow.cpp | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 954443a8d6e..03cfb373e48 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -43,7 +43,7 @@ class TestValueFlow : public TestFixture { TestValueFlow() : TestFixture("TestValueFlow") {} private: - /*const*/ Settings settings = settingsBuilder().library("std.cfg").build(); + const Settings settings = settingsBuilder().library("std.cfg").build(); void run() override { @@ -430,9 +430,10 @@ class TestValueFlow : public TestFixture { return false; } - bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, int value, ValueFlow::Value::ValueType type) { + bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, int value, ValueFlow::Value::ValueType type, const Settings* s = nullptr) { + const Settings& curSettings = s ? *s : settings; // Tokenize.. - SimpleTokenizer tokenizer(settings, *this); + SimpleTokenizer tokenizer(curSettings, *this); ASSERT_LOC(tokenizer.tokenize(code), file, line); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { @@ -5864,21 +5865,19 @@ class TestValueFlow : public TestFixture { ASSERT_EQUALS(false, value.isKnown()); // #13959 - const Settings settingsOld = settings; - settings.standards.c = Standards::C23; + const Settings settingsC23 = settingsBuilder(settings).c(Standards::C23).build(); code = "void f(int* p) {\n" " if (p == nullptr)\n" " return;\n" " if (p) {}\n" "}\n"; - value = valueOfTok(code, "p ) { }", &settings, /*cpp*/ false); + value = valueOfTok(code, "p ) { }", &settingsC23, /*cpp*/ false); ASSERT_EQUALS(1, value.intvalue); ASSERT_EQUALS(true, value.isKnown()); - settings.standards.c = Standards::C17; - value = valueOfTok(code, "p ) { }", &settings, /*cpp*/ false); + const Settings settingsC17 = settingsBuilder(settings).c(Standards::C17).build(); + value = valueOfTok(code, "p ) { }", &settingsC17, /*cpp*/ false); ASSERT(value == ValueFlow::Value()); - settings = settingsOld; } void valueFlowSizeofForwardDeclaredEnum() { @@ -7747,48 +7746,47 @@ class TestValueFlow : public TestFixture { void valueFlowDynamicBufferSize() { const char *code; - const Settings settingsOld = settings; // TODO: get rid of this - settings = settingsBuilder(settings).library("posix.cfg").library("bsd.cfg").build(); + const Settings settingsCfg = settingsBuilder(settings).library("posix.cfg").library("bsd.cfg").build(); code = "void* f() {\n" " void* x = malloc(10);\n" " return x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 3U, 10, ValueFlow::Value::ValueType::BUFFER_SIZE)); + ASSERT_EQUALS(true, testValueOfX(code, 3U, 10, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg)); code = "void* f() {\n" " void* x = calloc(4, 5);\n" " return x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 3U, 20, ValueFlow::Value::ValueType::BUFFER_SIZE)); + ASSERT_EQUALS(true, testValueOfX(code, 3U, 20, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg)); code = "void* f() {\n" " const char* y = \"abcd\";\n" " const char* x = strdup(y);\n" " return x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 4U, 5, ValueFlow::Value::ValueType::BUFFER_SIZE)); + ASSERT_EQUALS(true, testValueOfX(code, 4U, 5, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg)); code = "void* f() {\n" " void* y = malloc(10);\n" " void* x = realloc(y, 20);\n" " return x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 4U, 20, ValueFlow::Value::ValueType::BUFFER_SIZE)); + ASSERT_EQUALS(true, testValueOfX(code, 4U, 20, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg)); code = "void* f() {\n" " void* y = calloc(10, 4);\n" " void* x = reallocarray(y, 20, 5);\n" " return x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 4U, 100, ValueFlow::Value::ValueType::BUFFER_SIZE)); + ASSERT_EQUALS(true, testValueOfX(code, 4U, 100, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg)); code = "struct A {};\n" // #14305 "void* f() {\n" " A* x = new A();\n" " return x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 4U, 1, ValueFlow::Value::ValueType::BUFFER_SIZE)); + ASSERT_EQUALS(true, testValueOfX(code, 4U, 1, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg)); code = "struct A {};\n" "void* f() {\n" @@ -7796,7 +7794,7 @@ class TestValueFlow : public TestFixture { " return x;\n" "}"; { - auto values = tokenValues(code, "x ; }"); + auto values = tokenValues(code, "x ; }", &settingsCfg); ASSERT_EQUALS(1, values.size()); ASSERT(values.front().isSymbolicValue()); // TODO: add BUFFER_SIZE value = 1 @@ -7807,9 +7805,7 @@ class TestValueFlow : public TestFixture { " B* x = new B();\n" " return x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 4U, 4, ValueFlow::Value::ValueType::BUFFER_SIZE)); - - settings = settingsOld; + ASSERT_EQUALS(true, testValueOfX(code, 4U, 4, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg)); } void valueFlowSafeFunctionParameterValues() {