Skip to content

Commit 5443cd4

Browse files
committed
const
1 parent ea723c2 commit 5443cd4

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

test/testvalueflow.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class TestValueFlow : public TestFixture {
4343
TestValueFlow() : TestFixture("TestValueFlow") {}
4444

4545
private:
46-
/*const*/ Settings settings = settingsBuilder().library("std.cfg").build();
46+
const Settings settings = settingsBuilder().library("std.cfg").build();
4747

4848
void run() override {
4949

@@ -430,9 +430,10 @@ class TestValueFlow : public TestFixture {
430430
return false;
431431
}
432432

433-
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, int value, ValueFlow::Value::ValueType type) {
433+
bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, int value, ValueFlow::Value::ValueType type, const Settings* s = nullptr) {
434+
const Settings& curSettings = s ? *s : settings;
434435
// Tokenize..
435-
SimpleTokenizer tokenizer(settings, *this);
436+
SimpleTokenizer tokenizer(curSettings, *this);
436437
ASSERT_LOC(tokenizer.tokenize(code), file, line);
437438

438439
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
@@ -5864,21 +5865,19 @@ class TestValueFlow : public TestFixture {
58645865
ASSERT_EQUALS(false, value.isKnown());
58655866

58665867
// #13959
5867-
const Settings settingsOld = settings;
5868-
settings.standards.c = Standards::C23;
5868+
const Settings settingsC23 = settingsBuilder(settings).c(Standards::C23).build();
58695869
code = "void f(int* p) {\n"
58705870
" if (p == nullptr)\n"
58715871
" return;\n"
58725872
" if (p) {}\n"
58735873
"}\n";
5874-
value = valueOfTok(code, "p ) { }", &settings, /*cpp*/ false);
5874+
value = valueOfTok(code, "p ) { }", &settingsC23, /*cpp*/ false);
58755875
ASSERT_EQUALS(1, value.intvalue);
58765876
ASSERT_EQUALS(true, value.isKnown());
58775877

5878-
settings.standards.c = Standards::C17;
5879-
value = valueOfTok(code, "p ) { }", &settings, /*cpp*/ false);
5878+
const Settings settingsC17 = settingsBuilder(settings).c(Standards::C17).build();
5879+
value = valueOfTok(code, "p ) { }", &settingsC17, /*cpp*/ false);
58805880
ASSERT(value == ValueFlow::Value());
5881-
settings = settingsOld;
58825881
}
58835882

58845883
void valueFlowSizeofForwardDeclaredEnum() {
@@ -7747,56 +7746,55 @@ class TestValueFlow : public TestFixture {
77477746
void valueFlowDynamicBufferSize() {
77487747
const char *code;
77497748

7750-
const Settings settingsOld = settings; // TODO: get rid of this
7751-
settings = settingsBuilder(settings).library("posix.cfg").library("bsd.cfg").build();
7749+
const Settings settingsCfg = settingsBuilder(settings).library("posix.cfg").library("bsd.cfg").build();
77527750

77537751
code = "void* f() {\n"
77547752
" void* x = malloc(10);\n"
77557753
" return x;\n"
77567754
"}";
7757-
ASSERT_EQUALS(true, testValueOfX(code, 3U, 10, ValueFlow::Value::ValueType::BUFFER_SIZE));
7755+
ASSERT_EQUALS(true, testValueOfX(code, 3U, 10, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg));
77587756

77597757
code = "void* f() {\n"
77607758
" void* x = calloc(4, 5);\n"
77617759
" return x;\n"
77627760
"}";
7763-
ASSERT_EQUALS(true, testValueOfX(code, 3U, 20, ValueFlow::Value::ValueType::BUFFER_SIZE));
7761+
ASSERT_EQUALS(true, testValueOfX(code, 3U, 20, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg));
77647762

77657763
code = "void* f() {\n"
77667764
" const char* y = \"abcd\";\n"
77677765
" const char* x = strdup(y);\n"
77687766
" return x;\n"
77697767
"}";
7770-
ASSERT_EQUALS(true, testValueOfX(code, 4U, 5, ValueFlow::Value::ValueType::BUFFER_SIZE));
7768+
ASSERT_EQUALS(true, testValueOfX(code, 4U, 5, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg));
77717769

77727770
code = "void* f() {\n"
77737771
" void* y = malloc(10);\n"
77747772
" void* x = realloc(y, 20);\n"
77757773
" return x;\n"
77767774
"}";
7777-
ASSERT_EQUALS(true, testValueOfX(code, 4U, 20, ValueFlow::Value::ValueType::BUFFER_SIZE));
7775+
ASSERT_EQUALS(true, testValueOfX(code, 4U, 20, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg));
77787776

77797777
code = "void* f() {\n"
77807778
" void* y = calloc(10, 4);\n"
77817779
" void* x = reallocarray(y, 20, 5);\n"
77827780
" return x;\n"
77837781
"}";
7784-
ASSERT_EQUALS(true, testValueOfX(code, 4U, 100, ValueFlow::Value::ValueType::BUFFER_SIZE));
7782+
ASSERT_EQUALS(true, testValueOfX(code, 4U, 100, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg));
77857783

77867784
code = "struct A {};\n" // #14305
77877785
"void* f() {\n"
77887786
" A* x = new A();\n"
77897787
" return x;\n"
77907788
"}";
7791-
ASSERT_EQUALS(true, testValueOfX(code, 4U, 1, ValueFlow::Value::ValueType::BUFFER_SIZE));
7789+
ASSERT_EQUALS(true, testValueOfX(code, 4U, 1, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg));
77927790

77937791
code = "struct A {};\n"
77947792
"void* f() {\n"
77957793
" void* x = new A;\n"
77967794
" return x;\n"
77977795
"}";
77987796
{
7799-
auto values = tokenValues(code, "x ; }");
7797+
auto values = tokenValues(code, "x ; }", &settingsCfg);
78007798
ASSERT_EQUALS(1, values.size());
78017799
ASSERT(values.front().isSymbolicValue());
78027800
// TODO: add BUFFER_SIZE value = 1
@@ -7807,9 +7805,7 @@ class TestValueFlow : public TestFixture {
78077805
" B* x = new B();\n"
78087806
" return x;\n"
78097807
"}";
7810-
ASSERT_EQUALS(true, testValueOfX(code, 4U, 4, ValueFlow::Value::ValueType::BUFFER_SIZE));
7811-
7812-
settings = settingsOld;
7808+
ASSERT_EQUALS(true, testValueOfX(code, 4U, 4, ValueFlow::Value::ValueType::BUFFER_SIZE, &settingsCfg));
78137809
}
78147810

78157811
void valueFlowSafeFunctionParameterValues() {

0 commit comments

Comments
 (0)