Skip to content

Commit 518010a

Browse files
authored
Fix #14984: Valueflow: Buffer size not tracked across function calls (#8806)
1 parent 5e7baff commit 518010a

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7541,6 +7541,7 @@ void ValueFlow::setValues(TokenList& tokenlist,
75417541
VFA(valueFlowInferCondition(tokenlist, settings)),
75427542
VFA(valueFlowSwitchVariable(tokenlist, symboldatabase, errorLogger, settings)),
75437543
VFA(valueFlowForLoop(tokenlist, symboldatabase, errorLogger, settings)),
7544+
VFA(valueFlowDynamicBufferSize(tokenlist, symboldatabase, errorLogger, settings)),
75447545
VFA(valueFlowSubFunction(tokenlist, symboldatabase, errorLogger, settings)),
75457546
VFA(valueFlowFunctionReturn(tokenlist, errorLogger, settings)),
75467547
VFA(valueFlowLifetime(tokenlist, errorLogger, settings)),
@@ -7557,7 +7558,6 @@ void ValueFlow::setValues(TokenList& tokenlist,
75577558
});
75587559

75597560
runner.run_once({
7560-
VFA(valueFlowDynamicBufferSize(tokenlist, symboldatabase, errorLogger, settings)),
75617561
VFA(valueFlowDebug(tokenlist, errorLogger, settings)), // TODO: add option to print it after each step/iteration
75627562
});
75637563
}

test/cli/other_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ def test_progress(tmpdir):
210210
"progress: ValueFlow::valueFlowSwitchVariable(tokenlist, symboldatabase, errorLogger, settings) 1 100%\n"
211211
"progress: ValueFlow::valueFlowForLoop(tokenlist, symboldatabase, errorLogger, settings) 1 0%\n"
212212
"progress: ValueFlow::valueFlowForLoop(tokenlist, symboldatabase, errorLogger, settings) 1 100%\n"
213+
"progress: ValueFlow::valueFlowDynamicBufferSize(tokenlist, symboldatabase, errorLogger, settings) 1 0%\n"
214+
"progress: ValueFlow::valueFlowDynamicBufferSize(tokenlist, symboldatabase, errorLogger, settings) 1 100%\n"
213215
"progress: ValueFlow::valueFlowSubFunction(tokenlist, symboldatabase, errorLogger, settings) 1 0%\n"
214216
"progress: ValueFlow::valueFlowSubFunction(tokenlist, symboldatabase, errorLogger, settings) 1 100%\n"
215217
"progress: ValueFlow::valueFlowFunctionReturn(tokenlist, errorLogger, settings) 1 0%\n"

test/testvalueflow.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7939,6 +7939,17 @@ class TestValueFlow : public TestFixture {
79397939
" (void) x;\n"
79407940
"}\n";
79417941
ASSERT_EQUALS(true, testValueOfX(code, 4U, 0, ValueFlow::Value::ValueType::BUFFER_SIZE));
7942+
7943+
code = "void f(int *x)\n"
7944+
"{\n"
7945+
" *x = 1;\n"
7946+
"}\n"
7947+
"void g(void)\n"
7948+
"{\n"
7949+
" int *ptr = malloc(1234);\n"
7950+
" f(ptr);\n"
7951+
"}\n";
7952+
ASSERT_EQUALS(true, testValueOfX(code, 3U, 1234, ValueFlow::Value::ValueType::BUFFER_SIZE));
79427953
}
79437954

79447955
void valueFlowSafeFunctionParameterValues() {

0 commit comments

Comments
 (0)