Fix copy() to work with a vector that has trailing holes

Previously, the trailing holes would not be preserved in the copy.
This commit is contained in:
Jon Siwek 2021-04-19 19:23:04 -07:00
parent d00748a2e7
commit 819fc1aac0
3 changed files with 7 additions and 2 deletions

View file

@ -3706,8 +3706,7 @@ ValPtr VectorVal::DoClone(CloneState* state)
for ( auto i = 0; i < n; ++i )
{
auto elem = At(i);
if ( elem )
vv->Assign(i, elem->Clone(state));
vv->Assign(i, elem ? elem->Clone(state) : nullptr);
}
return vv;

View file

@ -75,3 +75,4 @@ slicing assignment grow (PASS)
slicing assignment shrink (PASS)
? operator (PASS)
copy of a vector with holes (PASS)
copy of a vector with trailing holes, [0, 2, 3, 77, , ], [0, 2, 3, 77, , ]

View file

@ -200,4 +200,9 @@ event zeek_init()
# Test copying of a vector with holes, as this used to crash.
local v19 = copy(v5);
test_case( "copy of a vector with holes", |v5| == |v19| );
# Even after removing some elements at the end, any trailing holes should
# be preserved after copying;
v5[6:] = vector();
local v20 = copy(v5);
print "copy of a vector with trailing holes", v5, v20;
}