mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 09:38:19 +00:00
Fix port/enum values SizeOf
not being a count
Really, they both should be count. But, they were getting provided as an integer. Port is easy since it is backed by an unsigned value. Enums *should* be unsigned, but aren't. This doesn't address that, it just takes the other name for this operator (absolute value) and makes the enum value positive if it's negative. This fixes a case where using the size of operator on enum/port values in certain contexts (like the default parameter of a struct) would cause an internal error.
This commit is contained in:
parent
ba91de59b0
commit
d3dd8a155d
4 changed files with 29 additions and 3 deletions
|
@ -20,6 +20,14 @@ type example_record: record {
|
|||
k: int &optional;
|
||||
};
|
||||
|
||||
type example_record_with_enum: record {
|
||||
e: count &default = |ENUM3|;
|
||||
} &redef;
|
||||
|
||||
type example_record_with_port: record {
|
||||
p: count &default = |80/tcp|;
|
||||
} &redef;
|
||||
|
||||
global a: addr = 1.2.3.4;
|
||||
global a6: addr = [::1];
|
||||
global b: bool = T;
|
||||
|
@ -36,6 +44,8 @@ global sn: subnet = 192.168.0.0/24;
|
|||
global t: table[string] of string;
|
||||
global ti: time = current_time();
|
||||
global v: vector of string;
|
||||
global with_enum: example_record_with_enum;
|
||||
global with_port: example_record_with_port;
|
||||
|
||||
# Additional initialization
|
||||
#
|
||||
|
@ -80,6 +90,9 @@ print fmt("Double %s: %f", d, |d|);
|
|||
# Size of enum: returns numeric value of enum constant.
|
||||
print fmt("Enum %s: %d", ENUM3, |ENUM3|);
|
||||
|
||||
# Within a record, enum sizeof should still be ok
|
||||
print fmt("Enum in record: %d %d", with_enum$e, |with_enum$e|);
|
||||
|
||||
# Size of file: returns current file size.
|
||||
# Note that this is a double so that file sizes >> 4GB
|
||||
# can be expressed.
|
||||
|
@ -97,6 +110,9 @@ print fmt("Interval %s: %f", iv, |iv|);
|
|||
# Size of port: returns port number as a count.
|
||||
print fmt("Port %s: %d", p, |p|);
|
||||
|
||||
# Within a record, port sizeof should still be ok
|
||||
print fmt("Port in record: %d %d", with_port$p, |with_port$p|);
|
||||
|
||||
# Size of record: returns number of fields (assigned + unassigned)
|
||||
print fmt("Record %s: %d", r, |r|);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue