diff --git a/src/CompHash.cc b/src/CompHash.cc index 763e5da463..8f80c26def 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -169,7 +169,7 @@ char* CompositeHash::SingleValHash(int type_check, char* kp0, { char* kp = kp0; RecordVal* rv = v->AsRecordVal(); - RecordType* rt = v->Type()->AsRecordType(); + RecordType* rt = bt->AsRecordType(); int num_fields = rt->NumFields(); for ( int i = 0; i < num_fields; ++i ) diff --git a/testing/btest/Baseline/language.set-opt-record-index/output b/testing/btest/Baseline/language.set-opt-record-index/output new file mode 100644 index 0000000000..fdc6f9d723 --- /dev/null +++ b/testing/btest/Baseline/language.set-opt-record-index/output @@ -0,0 +1,16 @@ +{ +[a=1, b=], +[a=4, b=5], +[a=3, b=] +} + +[a=1, b=] +[a=4, b=5] +[a=3, b=] + +T +F + +T +F +T diff --git a/testing/btest/language/set-opt-record-index.bro b/testing/btest/language/set-opt-record-index.bro new file mode 100644 index 0000000000..18ec963809 --- /dev/null +++ b/testing/btest/language/set-opt-record-index.bro @@ -0,0 +1,55 @@ +# @TEST-EXEC: bro %INPUT >output 2>&1 +# @TEST-EXEC: btest-diff output + +# Make sure a set can be indexed with a record that has optional fields + +type FOO: record { + a: count; + b: count &optional; +}; + +event bro_init() + { + local set_of_foo: set[FOO] = set(); + + local f: FOO; + f$a = 1; + + add set_of_foo[f]; + add set_of_foo[[$a=3]]; + + local f3: FOO; # = [$a=4, $b=5]; + f3$a = 4; + f3$b = 5; + + add set_of_foo[f3]; + + add set_of_foo[[$a=4, $b=5]]; + + print set_of_foo; + + print ""; + + for ( i in set_of_foo ) + print i; + + print ""; + + local f2: FOO; + f2$a = 2; + + print f in set_of_foo; + print f2 in set_of_foo; + + print ""; + + f3$a = 4; + print f3 in set_of_foo; + + f3$b = 4; + print f3 in set_of_foo; + + f3$b = 5; + print f3 in set_of_foo; + + }