mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 21:48:21 +00:00
cat_sep: Make fully vararg and do explicit runtime type checks
Using positional and vararg arguments for BIFs, it's not possible to do proper runtime type checking on them as discussed in #2425. The bifcl produced code unconditionally attempts to convert the positional arguments to StringVals, but nothing ever type checks them. Instead of improving the vararg support in Zeek script and bifcl, align cat_sep() with fmt() in making it fully vararg and do implement type checks by hand. With this change, passing wrong types for the separator and default argument isn't a fatal error anymore and the error messages are also more descriptive. It's a bit of a crutch working around varargs limitations. Fixes #2425
This commit is contained in:
parent
096ff41966
commit
a5f04b6270
10 changed files with 83 additions and 13 deletions
|
@ -4,4 +4,5 @@ foo3T
|
|||
3T
|
||||
foo|3|T
|
||||
|
||||
<empty>
|
||||
<empty>|3|T
|
||||
|
|
2
testing/btest/Baseline/bifs.cat_sep_errors-2/.stderr
Normal file
2
testing/btest/Baseline/bifs.cat_sep_errors-2/.stderr
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/cat_sep_errors.zeek, line 3: cat_sep() takes at least 2 arguments, got 1 (cat_sep(sep))
|
2
testing/btest/Baseline/bifs.cat_sep_errors-3/.stderr
Normal file
2
testing/btest/Baseline/bifs.cat_sep_errors-3/.stderr
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/cat_sep_errors.zeek, line 4: expected type string for default, got count (cat_sep(sep, 1))
|
2
testing/btest/Baseline/bifs.cat_sep_errors-4/.stderr
Normal file
2
testing/btest/Baseline/bifs.cat_sep_errors-4/.stderr
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/cat_sep_errors.zeek, line 4: expected type string for separator, got count (cat_sep(1, default))
|
2
testing/btest/Baseline/bifs.cat_sep_errors-5/.stderr
Normal file
2
testing/btest/Baseline/bifs.cat_sep_errors-5/.stderr
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/cat_sep_errors.zeek, line 3: expected type string for separator, got record (cat_sep([$a=1], default))
|
2
testing/btest/Baseline/bifs.cat_sep_errors/.stderr
Normal file
2
testing/btest/Baseline/bifs.cat_sep_errors/.stderr
Normal file
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/cat_sep_errors.zeek, line 6: cat_sep() takes at least 2 arguments, got 0 (cat_sep())
|
|
@ -17,6 +17,8 @@ event zeek_init()
|
|||
print cat_sep("|", "<empty>", a, b, c);
|
||||
|
||||
print cat_sep("|", "<empty>");
|
||||
|
||||
|
||||
print cat_sep("|", "<empty>", "");
|
||||
|
||||
print cat_sep("|", "<empty>", "", b, c);
|
||||
}
|
||||
|
|
33
testing/btest/bifs/cat_sep_errors.zeek
Normal file
33
testing/btest/bifs/cat_sep_errors.zeek
Normal file
|
@ -0,0 +1,33 @@
|
|||
# @TEST-DOC: Runtime errors calling cat_sep()
|
||||
# @TEST-EXEC: zeek -b %INPUT
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
|
||||
event zeek_init()
|
||||
{
|
||||
print cat_sep();
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
event zeek_init()
|
||||
{
|
||||
print cat_sep("sep");
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
# bad types 1
|
||||
event zeek_init()
|
||||
{
|
||||
print cat_sep("sep", 1);
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
# bad types 2
|
||||
event zeek_init()
|
||||
{
|
||||
print cat_sep(1, "default");
|
||||
}
|
||||
|
||||
@TEST-START-NEXT
|
||||
event zeek_init()
|
||||
{
|
||||
print cat_sep([$a=1], "default");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue