Skip to content
Snippets Groups Projects
Commit 99c53b97 authored by cznic's avatar cznic
Browse files

value.go: do not panic on negative shift amount

parent df048907
No related branches found
Tags v4.21.3
No related merge requests found
......@@ -5,6 +5,7 @@
package cc // import "modernc.org/cc/v4"
import (
"fmt"
"math/big"
)
......@@ -651,6 +652,11 @@ func (n *ShiftExpression) eval(c *ctx, mode flags) (r Value) {
case *UnknownValue:
// nop
case Int64Value:
if y < 0 {
c.errors.add(fmt.Errorf("%v: negative shift amount: %v << %v", position(n), x, y))
break
}
n.val = convert(x<<y, n.Type())
case UInt64Value:
n.val = convert(x<<y, n.Type())
......@@ -662,6 +668,11 @@ func (n *ShiftExpression) eval(c *ctx, mode flags) (r Value) {
case *UnknownValue:
// nop
case Int64Value:
if y < 0 {
c.errors.add(fmt.Errorf("%v: negative shift amount: %v << %v", position(n), x, y))
break
}
n.val = convert(x<<y, n.Type())
case UInt64Value:
n.val = convert(x<<y, n.Type())
......@@ -680,6 +691,11 @@ func (n *ShiftExpression) eval(c *ctx, mode flags) (r Value) {
case *UnknownValue:
// nop
case Int64Value:
if y < 0 {
c.errors.add(fmt.Errorf("%v: negative shift amount: %v >> %v", position(n), x, y))
break
}
n.val = convert(x>>y, n.Type())
case UInt64Value:
n.val = convert(x>>y, n.Type())
......@@ -691,6 +707,11 @@ func (n *ShiftExpression) eval(c *ctx, mode flags) (r Value) {
case *UnknownValue:
// nop
case Int64Value:
if y < 0 {
c.errors.add(fmt.Errorf("%v: negative shift amount: %v >> %v", position(n), x, y))
break
}
n.val = convert(x>>y, n.Type())
case UInt64Value:
n.val = convert(x>>y, n.Type())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment