diff --git a/CHANGES b/CHANGES index 10e1ccfc4b..6c479fed9d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,21 @@ +7.2.0-dev.228 | 2025-02-24 11:37:42 -0700 + + * Fix incorrect syntax for static_cast in to_count that I introduced in a previous merge (Mark Overholser) + + * Update baselines after changes to to_count and to_int (Mark Overholser) + + * fix to_count in zeek.bif to resolve conflict from bbanier's adjustment to static casting of the return from strtoull (Mark Overholser) + + * Fix tests in to_count to reflect appropriate function; add tests for 0x-formatted hex values for to_count and to_int (Mark Overholser) + + * update BIFs to_int() and to_count() to accept optional 'base' argument; allows more more exotic conversions from hex, octal, binary (Mark Overholser) + + * 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 (Mark Overholser) + + * geneve/functions.bif: Fix :zeek:see directive, take two (Arne Welzel, Corelight) + + * geneve/functions.bif: Fix :zeek:see directive (Arne Welzel, Corelight) + 7.2.0-dev.217 | 2025-02-22 12:33:25 -0800 * PacketAnalyzer::Geneve: Add get_options() (Arne Welzel, Corelight) diff --git a/VERSION b/VERSION index a6c4c71080..f9bafca8cd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -7.2.0-dev.217 +7.2.0-dev.228 diff --git a/src/zeek.bif b/src/zeek.bif index b96dfc842a..7d9320ad3b 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -2608,12 +2608,12 @@ function enum_to_int%(e: any%): int ## Returns: The :zeek:type:`string` *str* as :zeek:type:`int`. ## ## .. zeek:see:: to_addr to_port to_subnet -function to_int%(str: string%): int +function to_int%(str: string, base: count &default=10%): int %{ const char* s = str->CheckString(); char* end_s; - zeek_int_t i = strtoll(s, &end_s, 10); + zeek_int_t i = strtoll(s, &end_s, base); if ( s[0] == '\0' || std::any_of(static_cast(end_s), s + ::strlen(s), [](char c) { return ! (c == '\0' || ::isspace(c)); }) ) @@ -2676,12 +2676,12 @@ function double_to_count%(d: double%): count ## an invalid format. ## ## .. zeek:see:: to_addr to_int to_port to_subnet -function to_count%(str: string%): count +function to_count%(str: string, base: count &default=10%): count %{ const char* s = str->CheckString(); char* end_s; - uint64_t u = static_cast(strtoull(s, &end_s, 10)); + uint64_t u = static_cast(strtoull(s, &end_s, base)); if ( s[0] == '\0' || std::any_of(static_cast(end_s), s + ::strlen(s), [](char c) { return ! (c == '\0' || ::isspace(c)); }) ) diff --git a/testing/btest/Baseline/bifs.to_count/err b/testing/btest/Baseline/bifs.to_count/err index 1b96f363d0..2e4b081b1e 100644 --- a/testing/btest/Baseline/bifs.to_count/err +++ b/testing/btest/Baseline/bifs.to_count/err @@ -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) diff --git a/testing/btest/Baseline/bifs.to_count/out b/testing/btest/Baseline/bifs.to_count/out index d727a32bbe..7404ddbeb0 100644 --- a/testing/btest/Baseline/bifs.to_count/out +++ b/testing/btest/Baseline/bifs.to_count/out @@ -8,6 +8,10 @@ 18446744073709551611 205 206 +172 +35 +195 +195 0 123 9223372036854775808 and 9223372036854775808 are the same diff --git a/testing/btest/Baseline/bifs.to_int/err b/testing/btest/Baseline/bifs.to_int/err index 1e9d23dcb2..3c92cb6ef9 100644 --- a/testing/btest/Baseline/bifs.to_int/err +++ b/testing/btest/Baseline/bifs.to_int/err @@ -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) diff --git a/testing/btest/Baseline/bifs.to_int/out b/testing/btest/Baseline/bifs.to_int/out index 7ba7c89957..9527cdaf52 100644 --- a/testing/btest/Baseline/bifs.to_int/out +++ b/testing/btest/Baseline/bifs.to_int/out @@ -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 diff --git a/testing/btest/Baseline/language.assert-3/out b/testing/btest/Baseline/language.assert-3/out index 5a58147fa5..5194c63015 100644 --- a/testing/btest/Baseline/language.assert-3/out +++ b/testing/btest/Baseline/language.assert-3/out @@ -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 diff --git a/testing/btest/Baseline/language.assert-hook-2/out b/testing/btest/Baseline/language.assert-hook-2/out index f898a52732..bfd0473f20 100644 --- a/testing/btest/Baseline/language.assert-hook-2/out +++ b/testing/btest/Baseline/language.assert-hook-2/out @@ -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 diff --git a/testing/btest/Baseline/language.assert-misc/out b/testing/btest/Baseline/language.assert-misc/out index 1e529fdcaf..b072ff767c 100644 --- a/testing/btest/Baseline/language.assert-misc/out +++ b/testing/btest/Baseline/language.assert-misc/out @@ -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 { diff --git a/testing/btest/bifs/to_count.zeek b/testing/btest/bifs/to_count.zeek index 1e1ed72c2e..84bc1220ef 100644 --- a/testing/btest/bifs/to_count.zeek +++ b/testing/btest/bifs/to_count.zeek @@ -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; diff --git a/testing/btest/bifs/to_int.zeek b/testing/btest/bifs/to_int.zeek index 82d789dcea..fc964e1be6 100644 --- a/testing/btest/bifs/to_int.zeek +++ b/testing/btest/bifs/to_int.zeek @@ -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.