mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/timw/bit-shift-error-handling'
* origin/topic/timw/bit-shift-error-handling: Add btest for vector bit-shift operators Handle error cases for bit-shift operators more cleanly
This commit is contained in:
commit
6d16f9bb42
6 changed files with 53 additions and 5 deletions
6
CHANGES
6
CHANGES
|
@ -1,3 +1,9 @@
|
|||
5.1.0-dev.301 | 2022-07-29 12:10:20 -0700
|
||||
|
||||
* Add btest for vector bit-shift operators (Tim Wojtulewicz, Corelight)
|
||||
|
||||
* Handle error cases for bit-shift operators more cleanly (Tim Wojtulewicz, Corelight)
|
||||
|
||||
5.1.0-dev.298 | 2022-07-29 12:00:57 -0700
|
||||
|
||||
* Update 3rdparty submodule to get patricia reformat (Tim Wojtulewicz, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
5.1.0-dev.298
|
||||
5.1.0-dev.301
|
||||
|
|
40
src/Expr.cc
40
src/Expr.cc
|
@ -960,11 +960,47 @@ ValPtr BinaryExpr::Fold(Val* v1, Val* v2) const
|
|||
DO_UINT_FOLD(^);
|
||||
break;
|
||||
case EXPR_LSHIFT:
|
||||
DO_INT_FOLD(<<);
|
||||
{
|
||||
if ( is_integral )
|
||||
{
|
||||
if ( i2 < 0 )
|
||||
RuntimeError("left shift by negative value");
|
||||
else if ( i1 < 1 )
|
||||
RuntimeError("left shifting a negative number is undefined");
|
||||
|
||||
i3 = i1 << i2;
|
||||
}
|
||||
else if ( is_unsigned )
|
||||
{
|
||||
if ( u2 < 0 )
|
||||
RuntimeError("left shift by negative value");
|
||||
|
||||
u3 = u1 << u2;
|
||||
}
|
||||
else
|
||||
RuntimeErrorWithCallStack("bad type in BinaryExpr::Fold");
|
||||
break;
|
||||
}
|
||||
case EXPR_RSHIFT:
|
||||
DO_INT_FOLD(>>);
|
||||
{
|
||||
if ( is_integral )
|
||||
{
|
||||
if ( i2 < 0 )
|
||||
RuntimeError("right shift by negative value");
|
||||
|
||||
i3 = i1 >> i2;
|
||||
}
|
||||
else if ( is_unsigned )
|
||||
{
|
||||
if ( u2 < 0 )
|
||||
RuntimeError("right shift by negative value");
|
||||
|
||||
u3 = u1 >> u2;
|
||||
}
|
||||
else
|
||||
RuntimeErrorWithCallStack("bad type in BinaryExpr::Fold");
|
||||
break;
|
||||
}
|
||||
|
||||
case EXPR_AND_AND:
|
||||
DO_INT_FOLD(&&);
|
||||
|
|
|
@ -18,6 +18,7 @@ modulus operator (PASS)
|
|||
division operator (PASS)
|
||||
assignment operator (PASS)
|
||||
assignment operator (PASS)
|
||||
bitwise lshift (PASS)
|
||||
bitwise rshift (PASS)
|
||||
max int value = 9223372036854775807 (PASS)
|
||||
min int value = -9223372036854775808 (PASS)
|
||||
|
|
|
@ -54,7 +54,8 @@ event zeek_init()
|
|||
test_case( "assignment operator", i2 == 7 );
|
||||
i2 -= 2;
|
||||
test_case( "assignment operator", i2 == 5 );
|
||||
test_case( "bitwise rshift", i10 >> 1 == -6 );
|
||||
test_case( "bitwise lshift", i6 << 1 == 24 );
|
||||
test_case( "bitwise rshift", i6 >> 1 == 6 );
|
||||
|
||||
# Max/min value tests
|
||||
|
||||
|
@ -68,4 +69,3 @@ event zeek_init()
|
|||
test_case( str4, str4 == "min int value = -9223372036854775808" );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -226,4 +226,9 @@ event zeek_init()
|
|||
v21[3:] = vector();
|
||||
print "hole in vector of managed types after replacing slice", |v21|, v21;
|
||||
|
||||
# Test << and >> operators.
|
||||
local v22 = v6 << 1;
|
||||
local v23 = v6 >> 1;
|
||||
test_case( "left shift", all_set(v22 == vector(20, 40, 60)) );
|
||||
test_case( "right shift", all_set(v23 == vector(5, 10, 15)) );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue