mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Also trim trailing spaces in to_count
/to_int
inputs
Previously we would already trim leading spaces in inputs to `to_count` and `to_int`, effectively by just passing the behavior of the low-level functions used in their implementations to the user. While this was useful it was also inconsistent in that we did not allow trailing spaces which we enable with this patch.
This commit is contained in:
parent
55533e12d4
commit
d421a19691
4 changed files with 11 additions and 8 deletions
15
src/zeek.bif
15
src/zeek.bif
|
@ -14,6 +14,7 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -2614,8 +2615,11 @@ function to_int%(str: string%): int
|
||||||
|
|
||||||
zeek_int_t i = strtoll(s, &end_s, 10);
|
zeek_int_t i = strtoll(s, &end_s, 10);
|
||||||
|
|
||||||
if ( s[0] == '\0' || end_s[0] != '\0' )
|
if ( s[0] == '\0' || std::any_of(static_cast<const char*>(end_s), s + ::strlen(s),
|
||||||
|
[](char c) { return ! (c == '\0' || ::isspace(c)); }) )
|
||||||
|
{
|
||||||
zeek::emit_builtin_error("bad conversion to integer", @ARG@[0]);
|
zeek::emit_builtin_error("bad conversion to integer", @ARG@[0]);
|
||||||
|
}
|
||||||
|
|
||||||
return zeek::val_mgr->Int(i);
|
return zeek::val_mgr->Int(i);
|
||||||
%}
|
%}
|
||||||
|
@ -2679,11 +2683,12 @@ function to_count%(str: string%): count
|
||||||
|
|
||||||
uint64_t u = static_cast<uint64_t>(strtoull(s, &end_s, 10));
|
uint64_t u = static_cast<uint64_t>(strtoull(s, &end_s, 10));
|
||||||
|
|
||||||
if ( s[0] == '\0' || end_s[0] != '\0' )
|
if ( s[0] == '\0' || std::any_of(static_cast<const char*>(end_s), s + ::strlen(s),
|
||||||
{
|
[](char c) { return ! (c == '\0' || ::isspace(c)); }) )
|
||||||
|
{
|
||||||
zeek::emit_builtin_error("bad conversion to count", @ARG@[0]);
|
zeek::emit_builtin_error("bad conversion to count", @ARG@[0]);
|
||||||
u = 0;
|
u = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return zeek::val_mgr->Count(u);
|
return zeek::val_mgr->Count(u);
|
||||||
%}
|
%}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### 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 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 20: bad conversion to count (to_count() and )
|
||||||
error in <...>/to_count.zeek, line 24: bad conversion to count (to_count(206 ) and 206 )
|
|
||||||
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 25: bad conversion to count (to_count(not a count) and not a count)
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
0
|
0
|
||||||
18446744073709551611
|
18446744073709551611
|
||||||
205
|
205
|
||||||
0
|
206
|
||||||
0
|
0
|
||||||
123
|
123
|
||||||
9223372036854775808 and 9223372036854775808 are the same
|
9223372036854775808 and 9223372036854775808 are the same
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### 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 10: bad conversion to integer (to_int(not an int) and not an int)
|
||||||
error in <...>/to_int.zeek, line 13: bad conversion to integer (to_int(206 ) and 206 )
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue