diff --git a/src/Val.cc b/src/Val.cc index b98408e551..43f69c6c47 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -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; diff --git a/testing/btest/Baseline/language.vector/out b/testing/btest/Baseline/language.vector/out index 059395ac75..8e6c4572b6 100644 --- a/testing/btest/Baseline/language.vector/out +++ b/testing/btest/Baseline/language.vector/out @@ -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, , ] diff --git a/testing/btest/language/vector.zeek b/testing/btest/language/vector.zeek index 7b2b3e71c0..0fdd02fd66 100644 --- a/testing/btest/language/vector.zeek +++ b/testing/btest/language/vector.zeek @@ -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; }