Skip to content

Commit bc34f02

Browse files
committed
Disable the subfunction value flow analysis. It does not work well and needs to be rewritten. There are false positives.
1 parent c58385f commit bc34f02

7 files changed

Lines changed: 24 additions & 37 deletions

File tree

lib/valueflow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4152,7 +4152,8 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
41524152
// passed values are not "known"..
41534153
changeKnownToPossible(argvalues);
41544154

4155-
valueFlowInjectParameter(tokenlist, errorLogger, settings, argvar, calledFunctionScope, argvalues);
4155+
// FIXME: We need to rewrite the valueflow analysis of function calls. This does not work well.
4156+
//valueFlowInjectParameter(tokenlist, errorLogger, settings, argvar, calledFunctionScope, argvalues);
41564157
}
41574158
}
41584159
}

test/testbufferoverrun.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class TestBufferOverrun : public TestFixture {
368368
" str[i] = 0;\n"
369369
"}\n"
370370
"void b() { a(16); }");
371-
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", errout.str());
371+
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", "", errout.str());
372372
}
373373

374374

@@ -4130,7 +4130,7 @@ class TestBufferOverrun : public TestFixture {
41304130
" int a[sz];\n"
41314131
"}\n"
41324132
"void x() { f(-100); }");
4133-
ASSERT_EQUALS("[test.cpp:2]: (error) Declaration of array 'a' with negative size is undefined behaviour\n", errout.str());
4133+
TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Declaration of array 'a' with negative size is undefined behaviour\n", "", errout.str());
41344134

41354135
// don't warn for constant sizes -> this is a compiler error so this is used for static assertions for instance
41364136
check("int x, y;\n"

test/testnullpointer.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,9 +1345,8 @@ class TestNullPointer : public TestFixture {
13451345
" int i = s ? s->value + 1 \n"
13461346
" : s->value - 1; // <-- null ptr dereference \n"
13471347
" return i;\n"
1348-
"}\n"
1349-
"int main(){f(0);}\n", true);
1350-
ASSERT_EQUALS("[test.cpp:4]: (warning) Possible null pointer dereference: s\n", errout.str());
1348+
"}\n");
1349+
TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Possible null pointer dereference: s\n", "", errout.str());
13511350
}
13521351

13531352
void nullpointer30() { // #6392
@@ -2596,7 +2595,7 @@ class TestNullPointer : public TestFixture {
25962595
" p = s - 20;\n"
25972596
"}\n"
25982597
"void bar() { foo(0); }\n");
2599-
ASSERT_EQUALS("[test.cpp:2]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n", errout.str());
2598+
TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n", "", errout.str());
26002599

26012600
check("void foo(char *s) {\n"
26022601
" if (!s) {}\n"
@@ -2608,7 +2607,7 @@ class TestNullPointer : public TestFixture {
26082607
" s -= 20;\n"
26092608
"}\n"
26102609
"void bar() { foo(0); }\n");
2611-
ASSERT_EQUALS("[test.cpp:2]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n", errout.str());
2610+
TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n", "", errout.str());
26122611

26132612
check("void foo(char *s) {\n"
26142613
" if (!s) {}\n"
@@ -2628,7 +2627,7 @@ class TestNullPointer : public TestFixture {
26282627
" char * p = s + 20;\n"
26292628
"}\n"
26302629
"void bar() { foo(0); }\n");
2631-
ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout.str());
2630+
TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", "", errout.str());
26322631

26332632
check("void foo(char *s) {\n"
26342633
" if (!s) {}\n"
@@ -2640,7 +2639,7 @@ class TestNullPointer : public TestFixture {
26402639
" char * p = 20 + s;\n"
26412640
"}\n"
26422641
"void bar() { foo(0); }\n");
2643-
ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout.str());
2642+
TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", "", errout.str());
26442643

26452644
check("void foo(char *s) {\n"
26462645
" if (!s) {}\n"
@@ -2652,7 +2651,7 @@ class TestNullPointer : public TestFixture {
26522651
" s += 20;\n"
26532652
"}\n"
26542653
"void bar() { foo(0); }\n");
2655-
ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout.str());
2654+
TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", "", errout.str());
26562655

26572656
check("void foo(char *s) {\n"
26582657
" if (!s) {}\n"
@@ -2708,7 +2707,7 @@ class TestNullPointer : public TestFixture {
27082707
"int main() {\n"
27092708
" call(4,0);\n"
27102709
"}");
2711-
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1]: (error) Null pointer dereference: p\n", errout.str());
2710+
TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1]: (error) Null pointer dereference: p\n", "", errout.str());
27122711

27132712
ctu("void dostuff(int *x, int *y) {\n"
27142713
" if (!var)\n"

test/testother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ class TestOther : public TestFixture {
560560
" f1(123,y);\n"
561561
" if (y>0){}\n"
562562
"}");
563-
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1.\n", errout.str());
563+
TODO_ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:1]: (warning) Either the condition 'y>0' is redundant or there is division by zero at line 1.\n", "", errout.str());
564564

565565
// avoid false positives when variable is changed after division
566566
check("void f() {\n"

test/teststring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class TestString : public TestFixture {
9898
" char* s = \"Y\";\n"
9999
" foo_FP1(s);\n"
100100
"}");
101-
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (error) Modifying string literal \"Y\" directly or indirectly is undefined behaviour.\n", errout.str());
101+
TODO_ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (error) Modifying string literal \"Y\" directly or indirectly is undefined behaviour.\n", "", errout.str());
102102

103103
check("void foo_FP1(char *p) {\n"
104104
" p[1] = 'B';\n"

test/testtype.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ class TestType : public TestFixture {
194194
" return x * y;\n"
195195
"}\n"
196196
"void f2() { f1(-4,4); }");
197-
ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious code: sign conversion of x in calculation, even though x can have a negative value\n", errout.str());
197+
TODO_ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious code: sign conversion of x in calculation, even though x can have a negative value\n", "", errout.str());
198198

199199
check("unsigned int f1(int x) {" // x has no signedness, but it can have the value -1 so assume it's signed
200200
" return x * 5U;\n"
201201
"}\n"
202202
"void f2() { f1(-4); }");
203-
ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious code: sign conversion of x in calculation, even though x can have a negative value\n", errout.str());
203+
TODO_ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious code: sign conversion of x in calculation, even though x can have a negative value\n", "", errout.str());
204204

205205
check("unsigned int f1(int x) {" // #6168: FP for inner calculation
206206
" return 5U * (1234 - x);\n" // <- signed subtraction, x is not sign converted

test/testvalueflow.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ class TestValueFlow : public TestFixture {
9090
TEST_CASE(valueFlowSwitchVariable);
9191

9292
TEST_CASE(valueFlowForLoop);
93-
TEST_CASE(valueFlowSubFunction);
94-
TEST_CASE(valueFlowSubFunctionLibrary);
93+
// TODO value flow in sub function
94+
//TEST_CASE(valueFlowSubFunction);
95+
//TEST_CASE(valueFlowSubFunctionLibrary);
9596
TEST_CASE(valueFlowFunctionReturn);
9697

9798
TEST_CASE(valueFlowFunctionDefaultParameter);
@@ -316,7 +317,7 @@ class TestValueFlow : public TestFixture {
316317
"}\n"
317318
"\n"
318319
"void test() { dostuff(\"abc\"); }";
319-
ASSERT_EQUALS(true, testValueOfX(code, 2, "\"abc\"", ValueFlow::Value::TOK));
320+
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 2, "\"abc\"", ValueFlow::Value::TOK));
320321
}
321322

322323
void valueFlowPointerAlias() {
@@ -687,14 +688,6 @@ class TestValueFlow : public TestFixture {
687688
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
688689

689690
// function call => calculation
690-
code = "void f(int x) {\n"
691-
" a = x + 8;\n"
692-
"}\n"
693-
"void callf() {\n"
694-
" f(7);\n"
695-
"}";
696-
ASSERT_EQUALS(15, valueOfTok(code, "+").intvalue);
697-
698691
code = "void f(int x, int y) {\n"
699692
" a = x + y;\n"
700693
"}\n"
@@ -929,9 +922,10 @@ class TestValueFlow : public TestFixture {
929922
" int x = 3;\n"
930923
" f1(x+1);\n"
931924
"}\n";
932-
ASSERT_EQUALS("5,Assignment 'x=3', assigned value is 3\n"
933-
"6,Calling function 'f1', 1st argument 'x+1' value is 4\n",
934-
getErrorPathForX(code, 2U));
925+
TODO_ASSERT_EQUALS("5,Assignment 'x=3', assigned value is 3\n"
926+
"6,Calling function 'f1', 1st argument 'x+1' value is 4\n",
927+
"",
928+
getErrorPathForX(code, 2U));
935929

936930
code = "void f(int a) {\n"
937931
" int x;\n"
@@ -3133,13 +3127,6 @@ class TestValueFlow : public TestFixture {
31333127
"}";
31343128
ASSERT(isNotKnownValues(code, ">"));
31353129

3136-
// function
3137-
code = "int f(int x) { return x + 1; }\n" // <- possible value
3138-
"void a() { f(12); }";
3139-
value = valueOfTok(code, "+");
3140-
ASSERT_EQUALS(13, value.intvalue);
3141-
ASSERT(value.isPossible());
3142-
31433130
// known and possible value
31443131
code = "void f() {\n"
31453132
" int x = 1;\n"

0 commit comments

Comments
 (0)