ExprEngine: Passing array to function, array data might be overwritten

This commit is contained in:
Daniel Marjamäki 2019-09-21 19:34:06 +02:00
parent 962e7c790b
commit da91c139d5
2 changed files with 18 additions and 2 deletions

View File

@ -461,8 +461,16 @@ static ExprEngine::ValuePtr executeAssign(const Token *tok, Data &data)
static ExprEngine::ValuePtr executeFunctionCall(const Token *tok, Data &data)
{
for (const Token *argtok : getArguments(tok))
(void)executeExpression(argtok, data);
for (const Token *argtok : getArguments(tok)) {
auto val = executeExpression(argtok, data);
if (auto arrayValue = std::dynamic_pointer_cast<ExprEngine::ArrayValue>(val)) {
ValueType vt(*argtok->valueType());
vt.pointer = 0;
auto anyVal = getValueRangeFromValueType(data.getNewSymbolName(), &vt, *data.settings);
for (int i = 0; i < arrayValue->data.size(); ++i)
arrayValue->data[i] = anyVal;
}
}
auto val = getValueRangeFromValueType(data.getNewSymbolName(), tok->valueType(), *data.settings);
call(data.callbacks, tok, val);
return val;
@ -669,6 +677,9 @@ void ExprEngine::executeFunction(const Scope *functionScope, const Tokenizer *to
const Function *function = functionScope->function;
if (!function)
return;
if (functionScope->bodyStart->fileIndex() > 0)
// TODO.. what about functions in headers?
return;
int symbolValueIndex = 0;
TrackExecution trackExecution;

View File

@ -50,6 +50,7 @@ private:
TEST_CASE(localArray1);
TEST_CASE(localArray2);
TEST_CASE(localArray3);
TEST_CASE(localArrayUninit);
TEST_CASE(pointerAlias1);
@ -145,6 +146,10 @@ private:
ASSERT_EQUALS("0", getRange("inf f() { char arr[10] = \"\"; return arr[4]; }", "arr[4]"));
}
void localArray3() {
ASSERT_EQUALS("0:255", getRange("int f() { unsigned char arr[10] = \"\"; dostuff(arr); return arr[4]; }", "arr[4]"));
}
void localArrayUninit() {
ASSERT_EQUALS("?", getRange("inf f() { int arr[10]; return arr[4]; }", "arr[4]"));
}