mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +00:00
Switching vectors from being 1-based to 0-based.
This is obviously a change that break backwards-compatibility. I hope I caught all cases where vectors are used ... I've completely removed the VECTOR_MIN constant. Turns out that was already not working: some code pieces were nevertheless hard-coding the 1-based indexing ...
This commit is contained in:
parent
f564023a12
commit
4aa844aa87
10 changed files with 47 additions and 66 deletions
29
src/Val.cc
29
src/Val.cc
|
@ -3231,15 +3231,6 @@ bool VectorVal::Assign(unsigned int index, Val* element, const Expr* assigner,
|
|||
return false;
|
||||
}
|
||||
|
||||
if ( index == 0 || index > (1 << 30) )
|
||||
{
|
||||
if ( assigner )
|
||||
assigner->Error(fmt("index (%d) must be positive",
|
||||
index));
|
||||
Unref(element);
|
||||
return true; // true = "no fatal error"
|
||||
}
|
||||
|
||||
BroType* yt = Type()->AsVectorType()->YieldType();
|
||||
|
||||
if ( yt && yt->Tag() == TYPE_TABLE &&
|
||||
|
@ -3254,7 +3245,7 @@ bool VectorVal::Assign(unsigned int index, Val* element, const Expr* assigner,
|
|||
Val* ival = new Val(index, TYPE_COUNT);
|
||||
StateAccess::Log(new StateAccess(OP_ASSIGN_IDX,
|
||||
this, ival, element,
|
||||
(*val.vector_val)[index - 1]));
|
||||
(*val.vector_val)[index]));
|
||||
Unref(ival);
|
||||
}
|
||||
|
||||
|
@ -3264,10 +3255,10 @@ bool VectorVal::Assign(unsigned int index, Val* element, const Expr* assigner,
|
|||
}
|
||||
}
|
||||
|
||||
if ( index <= val.vector_val->size() )
|
||||
Unref((*val.vector_val)[index - 1]);
|
||||
if ( index < val.vector_val->size() )
|
||||
Unref((*val.vector_val)[index]);
|
||||
else
|
||||
val.vector_val->resize(index);
|
||||
val.vector_val->resize(index + 1);
|
||||
|
||||
if ( LoggingAccess() && op != OP_NONE )
|
||||
{
|
||||
|
@ -3278,14 +3269,14 @@ bool VectorVal::Assign(unsigned int index, Val* element, const Expr* assigner,
|
|||
|
||||
StateAccess::Log(new StateAccess(op == OP_INCR ?
|
||||
OP_INCR_IDX : OP_ASSIGN_IDX,
|
||||
this, ival, element, (*val.vector_val)[index - 1]));
|
||||
this, ival, element, (*val.vector_val)[index]));
|
||||
Unref(ival);
|
||||
}
|
||||
|
||||
// Note: we do *not* Ref() the element, if any, at this point.
|
||||
// AssignExpr::Eval() already does this; other callers must remember
|
||||
// to do it similarly.
|
||||
(*val.vector_val)[index - 1] = element;
|
||||
(*val.vector_val)[index] = element;
|
||||
|
||||
Modified();
|
||||
return true;
|
||||
|
@ -3294,7 +3285,7 @@ bool VectorVal::Assign(unsigned int index, Val* element, const Expr* assigner,
|
|||
bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many,
|
||||
Val* element, const Expr* assigner)
|
||||
{
|
||||
ResizeAtLeast(index + how_many - 1);
|
||||
ResizeAtLeast(index + how_many);
|
||||
|
||||
for ( unsigned int i = index; i < index + how_many; ++i )
|
||||
if ( ! Assign(i, element, assigner) )
|
||||
|
@ -3306,10 +3297,10 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many,
|
|||
|
||||
Val* VectorVal::Lookup(unsigned int index) const
|
||||
{
|
||||
if ( index == 0 || index > val.vector_val->size() )
|
||||
if ( index >= val.vector_val->size() )
|
||||
return 0;
|
||||
|
||||
return (*val.vector_val)[index - 1];
|
||||
return (*val.vector_val)[index];
|
||||
}
|
||||
|
||||
unsigned int VectorVal::Resize(unsigned int new_num_elements)
|
||||
|
@ -3398,7 +3389,7 @@ bool VectorVal::DoUnserialize(UnserialInfo* info)
|
|||
{
|
||||
Val* v;
|
||||
UNSERIALIZE_OPTIONAL(v, Val::Unserialize(info, TYPE_ANY));
|
||||
Assign(i + VECTOR_MIN, v, 0);
|
||||
Assign(i, v, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue