Fix indexing of set/table types with a vector

Previous behavor:

  internal error: bad index type in CompositeHash::ComputeSingletonHash
  Aborted (core dumped)
This commit is contained in:
Jon Siwek 2021-04-14 21:58:14 -07:00
parent fc3438bda5
commit 735ac0b4fa
3 changed files with 45 additions and 2 deletions

View file

@ -22,12 +22,13 @@ CompositeHash::CompositeHash(TypeListPtr composite_type)
{
singleton_tag = TYPE_INTERNAL_ERROR;
// If the only element is a record, don't treat it as a
// If the only element is a record or vector, don't treat it as a
// singleton, since it needs to be evaluated specially.
if ( type->GetTypes().size() == 1 )
{
if ( type->GetTypes()[0]->Tag() == TYPE_RECORD )
if ( type->GetTypes()[0]->Tag() == TYPE_RECORD ||
type->GetTypes()[0]->Tag() == TYPE_VECTOR)
{
is_complex_type = true;
is_singleton = false;

View file

@ -0,0 +1,18 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
{
[2, 3],
[4, 5, 6],
[1]
}
T
T
T
T
{
[[1], [2]] ,
[[1, 2], [3, 4, 5]]
}
T
T
T
T

View file

@ -0,0 +1,24 @@
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
local s: set[vector of count] = set();
local ss: set[vector of count, vector of count] = set();
add s[vector(1)];
add s[vector(2, 3)];
add s[vector(4, 5, 6)];
add ss[vector(1), vector(2)];
add ss[vector(1, 2), vector(3, 4, 5)];
print s;
print vector(1) in s;
print vector(2) !in s;
print vector(2, 3) in s;
print vector(4, 5, 6) in s;
print ss;
print [vector(1), vector(2)] in ss;
print [vector(1), vector(1)] !in ss;
print [vector(1, 2), vector(3, 4)] !in ss;
print [vector(1, 2), vector(3, 4, 5)] in ss;