mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
overlooked another way in which vector holes can be created
This commit is contained in:
parent
f43be3a206
commit
0f10c46f42
2 changed files with 18 additions and 9 deletions
24
src/Val.cc
24
src/Val.cc
|
@ -3269,8 +3269,11 @@ bool VectorVal::Assign(unsigned int index, ValPtr element)
|
|||
if ( ! CheckElementType(element) )
|
||||
return false;
|
||||
|
||||
if ( index >= vector_val->size() )
|
||||
auto n = vector_val->size();
|
||||
|
||||
if ( index >= n )
|
||||
{
|
||||
AddHoles(index - n);
|
||||
vector_val->resize(index + 1);
|
||||
if ( yield_types )
|
||||
yield_types->resize(index + 1);
|
||||
|
@ -3332,14 +3335,7 @@ bool VectorVal::Insert(unsigned int index, ValPtr element)
|
|||
it = vector_val->end();
|
||||
if ( yield_types )
|
||||
types_it = yield_types->end();
|
||||
|
||||
// Initialize any holes the assignment induces in the vector.
|
||||
TypePtr fill_t = yield_type;
|
||||
if ( yield_type->Tag() == TYPE_VOID )
|
||||
fill_t = base_type(TYPE_ANY);
|
||||
|
||||
for ( auto i = n; i < index; ++i )
|
||||
vector_val->emplace_back(ZVal(fill_t));
|
||||
AddHoles(index - n);
|
||||
}
|
||||
|
||||
if ( yield_types )
|
||||
|
@ -3355,6 +3351,16 @@ bool VectorVal::Insert(unsigned int index, ValPtr element)
|
|||
return true;
|
||||
}
|
||||
|
||||
void VectorVal::AddHoles(int nholes)
|
||||
{
|
||||
TypePtr fill_t = yield_type;
|
||||
if ( yield_type->Tag() == TYPE_VOID )
|
||||
fill_t = base_type(TYPE_ANY);
|
||||
|
||||
for ( auto i = 0; i < nholes; ++i )
|
||||
vector_val->emplace_back(ZVal(fill_t));
|
||||
}
|
||||
|
||||
bool VectorVal::Remove(unsigned int index)
|
||||
{
|
||||
if ( index >= vector_val->size() )
|
||||
|
|
|
@ -1571,6 +1571,9 @@ private:
|
|||
// element type-checked.
|
||||
bool CheckElementType(const ValPtr& element);
|
||||
|
||||
// Add the given number of "holes" to the end of a vector.
|
||||
void AddHoles(int nholes);
|
||||
|
||||
std::vector<ZVal>* vector_val;
|
||||
|
||||
// For homogeneous vectors (the usual case), the type of the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue