mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/index-opt-record'
* origin/topic/jsiwek/index-opt-record: Fix indexing for record types with optional fields Closes #378.
This commit is contained in:
commit
8d10a76eba
3 changed files with 72 additions and 1 deletions
|
@ -169,7 +169,7 @@ char* CompositeHash::SingleValHash(int type_check, char* kp0,
|
||||||
{
|
{
|
||||||
char* kp = kp0;
|
char* kp = kp0;
|
||||||
RecordVal* rv = v->AsRecordVal();
|
RecordVal* rv = v->AsRecordVal();
|
||||||
RecordType* rt = v->Type()->AsRecordType();
|
RecordType* rt = bt->AsRecordType();
|
||||||
int num_fields = rt->NumFields();
|
int num_fields = rt->NumFields();
|
||||||
|
|
||||||
for ( int i = 0; i < num_fields; ++i )
|
for ( int i = 0; i < num_fields; ++i )
|
||||||
|
|
16
testing/btest/Baseline/language.set-opt-record-index/output
Normal file
16
testing/btest/Baseline/language.set-opt-record-index/output
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
[a=1, b=<uninitialized>],
|
||||||
|
[a=4, b=5],
|
||||||
|
[a=3, b=<uninitialized>]
|
||||||
|
}
|
||||||
|
|
||||||
|
[a=1, b=<uninitialized>]
|
||||||
|
[a=4, b=5]
|
||||||
|
[a=3, b=<uninitialized>]
|
||||||
|
|
||||||
|
T
|
||||||
|
F
|
||||||
|
|
||||||
|
T
|
||||||
|
F
|
||||||
|
T
|
55
testing/btest/language/set-opt-record-index.bro
Normal file
55
testing/btest/language/set-opt-record-index.bro
Normal file
|
@ -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;
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue