diff --git a/NEWS b/NEWS index a78addb5de..1c5bde47dc 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,11 @@ New Functionality Changed Functionality --------------------- +- The for-loop index variable for vectors has been changed from + 'int' to 'count' type. It's unlikely this would alter/break any + script behavior unless they were explicitly inspecting the variable's + type (and there's typically no reason to do that). + Removed Functionality --------------------- diff --git a/doc/script-reference/types.rst b/doc/script-reference/types.rst index 1b15082058..e14f3d6dad 100644 --- a/doc/script-reference/types.rst +++ b/doc/script-reference/types.rst @@ -559,9 +559,8 @@ Here is a more detailed description of each type: .. bro:type:: vector - A vector is like a :bro:type:`table`, except it's always indexed by a - :bro:type:`count` (and vector indexing is always zero-based). A vector - is declared like: + A vector is like a :bro:type:`table`, except its indices are non-negative + integers, starting from zero. A vector is declared like: .. sourcecode:: bro diff --git a/src/Stmt.cc b/src/Stmt.cc index 26be70c373..162cc52d62 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1387,7 +1387,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, Expr* loop_expr) BroType* t = (*loop_vars)[0]->Type(); if ( ! t ) - delete add_local((*loop_vars)[0], base_type(TYPE_INT), + delete add_local((*loop_vars)[0], base_type(TYPE_COUNT), INIT_NONE, 0, 0, VAR_REGULAR); else if ( ! IsIntegral(t->Tag()) ) @@ -1470,7 +1470,7 @@ Val* ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const { VectorVal* vv = v->AsVectorVal(); - for ( int i = 0; i <= int(vv->Size()); ++i ) + for ( auto i = 0u; i <= vv->Size(); ++i ) { // Skip unassigned vector indices. if ( ! vv->Lookup(i) ) @@ -1479,7 +1479,7 @@ Val* ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const // Set the loop variable to the current index, and make // another pass over the loop body. f->SetElement((*loop_vars)[0]->Offset(), - new Val(i, TYPE_INT)); + new Val(i, TYPE_COUNT)); flow = FLOW_NEXT; ret = body->Exec(f, flow); diff --git a/testing/btest/language/vector.bro b/testing/btest/language/vector.bro index 85bed8eae2..0eafd6c60c 100644 --- a/testing/btest/language/vector.bro +++ b/testing/btest/language/vector.bro @@ -63,7 +63,7 @@ event bro_init() ct = 0; for ( c in v1 ) { - if ( type_name(c) != "int" ) + if ( type_name(c) != "count" ) print "Error: wrong index type"; if ( type_name(v1[c]) != "string" ) print "Error: wrong vector type";