Merge remote-tracking branch 'markoverholser/master'

* markoverholser/master:
  Fix incorrect syntax for static_cast in to_count that I introduced in a previous merge
  Update baselines after changes to to_count and to_int
  fix to_count in zeek.bif to resolve conflict from bbanier's adjustment to static casting of the return from strtoull
  Fix tests in to_count to reflect appropriate function; add tests for 0x-formatted hex values for to_count and to_int
  update BIFs to_int() and to_count() to accept optional 'base' argument; allows more more exotic conversions from hex, octal, binary
  Fixes #4076; update BIFs to_int() and to_count() to accept optional 'base' argument for more easy conversions of strings representing (for example) hexadecimal, octal, or binary numbers
This commit is contained in:
Tim Wojtulewicz 2025-02-24 11:37:42 -07:00
commit 66e3232dcc
12 changed files with 46 additions and 12 deletions

View file

@ -1,4 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/to_count.zeek, line 8: bad conversion to count (int_to_count(a) and -2)
error in <...>/to_count.zeek, line 20: bad conversion to count (to_count() and )
error in <...>/to_count.zeek, line 25: bad conversion to count (to_count(not a count) and not a count)
error in <...>/to_count.zeek, line 20: bad conversion to count (to_count(, 10) and )
error in <...>/to_count.zeek, line 29: bad conversion to count (to_count(not a count, 10) and not a count)

View file

@ -8,6 +8,10 @@
18446744073709551611
205
206
172
35
195
195
0
123
9223372036854775808 and 9223372036854775808 are the same

View file

@ -1,2 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/to_int.zeek, line 10: bad conversion to integer (to_int(not an int) and not an int)
error in <...>/to_int.zeek, line 14: bad conversion to integer (to_int(not an int, 10) and not an int)

View file

@ -1,6 +1,10 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
1
-1
188
39
243
243
4294967296
0
205

View file

@ -1,3 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/assert.zeek, line 3: assertion failure: (coerce to_count("42") to double) == 42.5 (always failing)
error in <...>/assert.zeek, line 3: assertion failure: (coerce to_count("42", 10) to double) == 42.5 (always failing)
fatal error: errors occurred while initializing

View file

@ -1,5 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
assertion_failure, to_count("5") == 4, 5 is not 4
assertion_failure, to_count("5", 10) == 4, 5 is not 4
assert <...>/assert-hook.zeek:21
f <...>/assert-hook.zeek:25
g <...>/assert-hook.zeek:26

View file

@ -3,9 +3,9 @@ f, lambda_<10820400278317158366>: function() : void
{
assert 0 < getpid(), fmt("my pid is funny: %s", getpid());
}
g, lambda_<9730512750166342063>: function() : void
g, lambda_<16208386833253569415>: function() : void
{
assert to_count("42") == 42;
assert to_count("42", 10) == 42;
}
test_function, test_function: function() : void
{

View file

@ -22,6 +22,10 @@ event zeek_init()
# We automatically trim leading, but not trailing whitespace.
print to_count(" 205"); # Okay.
print to_count("206 "); # Error.
print to_count("10101100", 2);
print to_count("43", 8);
print to_count("C3", 16);
print to_count("0xC3", 16);
print to_count("not a count");
local e: port = 123/tcp;

View file

@ -6,6 +6,10 @@ event zeek_init()
{
print to_int("1");
print to_int("-1");
print to_int("10111100", 2);
print to_int("47", 8);
print to_int("F3", 16);
print to_int("0xF3", 16);
print to_int("4294967296");
print to_int("not an int");
# We automatically trim leading, but not trailing whitespace.