mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Add type checking to string_cat arguments
This commit is contained in:
parent
686eb54f95
commit
ed4521af60
6 changed files with 37 additions and 0 deletions
|
@ -64,7 +64,15 @@ function string_cat%(...%): string
|
|||
%{
|
||||
int n = 0;
|
||||
for ( const auto& a : @ARG@ )
|
||||
{
|
||||
if ( a->GetType()->Tag() != TYPE_STRING )
|
||||
{
|
||||
zeek::reporter->Error("string_cat() requires string arguments");
|
||||
return val_mgr->EmptyString();
|
||||
}
|
||||
|
||||
n += a->AsString()->Len();
|
||||
}
|
||||
|
||||
u_char* b = new u_char[n+1];
|
||||
zeek::String* s = new zeek::String(1, b, n);
|
||||
|
|
|
@ -66,3 +66,6 @@ find_str: -1
|
|||
find_str: 4
|
||||
find_str: 4
|
||||
|
||||
string_cat
|
||||
-----------------------------------------------------
|
||||
string_cat: abc
|
||||
|
|
6
testing/btest/Baseline/bifs.string_utils_errors/.stderr
Normal file
6
testing/btest/Baseline/bifs.string_utils_errors/.stderr
Normal file
|
@ -0,0 +1,6 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error: Fill string passed to ljust() must be a single character
|
||||
error: Fill string passed to rjust() must be a single character
|
||||
error: find_str: end position must be greater than start position
|
||||
error: find_str: end position must be greater than start position
|
||||
error: string_cat() requires string arguments
|
|
@ -1,5 +1,12 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
Justification (input string 'abc')
|
||||
----------------------------------
|
||||
|
||||
find_str/rfind_str (input string 'abcdefghi')
|
||||
-----------------------------------------------------
|
||||
find_str: -1
|
||||
find_str: -1
|
||||
|
||||
string_cat
|
||||
-----------------------------------------------------
|
||||
string_cat:
|
||||
|
|
|
@ -78,4 +78,8 @@ event zeek_init()
|
|||
print fmt("find_str: %d", rfind_str(s3, "efg"));
|
||||
print fmt("find_str: %d", rfind_str(s3, "efg", 2, 6));
|
||||
print "";
|
||||
|
||||
print fmt("string_cat");
|
||||
print "-----------------------------------------------------";
|
||||
print fmt("string_cat: %s", string_cat("a", "b", "c"));
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#
|
||||
# @TEST-EXEC: zeek -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
# @TEST-EXEC: btest-diff .stderr
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
|
@ -12,8 +13,16 @@ event zeek_init()
|
|||
local s1 : string = "abc";
|
||||
print fmt("ljust: '%s'", ljust(s1, 2, "--")); # This should return an error
|
||||
print fmt("rjust: '%s'", rjust(s1, 2, "--")); # This should return an error
|
||||
print "";
|
||||
|
||||
local s3: string = "abcdefghi";
|
||||
print fmt("find_str/rfind_str (input string '%s')", s3);
|
||||
print "-----------------------------------------------------";
|
||||
print fmt("find_str: %d", find_str(s3, "efg", 6, 2));
|
||||
print fmt("find_str: %d", rfind_str(s3, "efg", 6, 2));
|
||||
print "";
|
||||
|
||||
print fmt("string_cat");
|
||||
print "-----------------------------------------------------";
|
||||
print fmt("string_cat: %s", string_cat("a", 1, "c"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue