Bug hunting; Remove old value from array when it is overwritten
This commit is contained in:
parent
d4860f500a
commit
8619bfe957
|
@ -929,6 +929,16 @@ void ExprEngine::ArrayValue::assign(ExprEngine::ValuePtr index, ExprEngine::Valu
|
|||
if (!index)
|
||||
data.clear();
|
||||
if (value) {
|
||||
if (index) {
|
||||
// Remove old item that will be "overwritten"
|
||||
for (size_t i = 0; i < data.size(); ++i) {
|
||||
if (data[i].index && data[i].index->name == index->name) {
|
||||
data.erase(data.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ExprEngine::ArrayValue::IndexAndValue indexAndValue = {index, value};
|
||||
data.push_back(indexAndValue);
|
||||
}
|
||||
|
|
|
@ -85,6 +85,7 @@ private:
|
|||
TEST_CASE(array4);
|
||||
TEST_CASE(array5);
|
||||
TEST_CASE(array6);
|
||||
TEST_CASE(array7);
|
||||
TEST_CASE(arrayInit1);
|
||||
TEST_CASE(arrayInit2);
|
||||
TEST_CASE(arrayInit3);
|
||||
|
@ -665,6 +666,19 @@ private:
|
|||
expr(code, "=="));
|
||||
}
|
||||
|
||||
void array7() {
|
||||
const char code[] = "void foo(unsigned char *x) {\n"
|
||||
" *x = 2;\n"
|
||||
" *x = 1;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS("1:28: $2=ArrayValue([$1],[:]=?,null)\n"
|
||||
"1:28: $1=IntRange(1:ffffffffffffffff)\n"
|
||||
"1:28: 0:memory:{x=($2,[$1],[:]=?)}\n"
|
||||
"2:9: 0:memory:{x=($2,[$1],[:]=?,[0]=2)}\n"
|
||||
"3:9: 0:memory:{x=($2,[$1],[:]=?,[0]=1)}\n",
|
||||
trackExecution(code));
|
||||
}
|
||||
|
||||
void arrayInit1() {
|
||||
ASSERT_EQUALS("0", getRange("inf f() { char arr[10] = \"\"; return arr[4]; }", "arr[4]"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue