proc/eval: Return an error when slicing a map over its length
Fixes #288
This commit is contained in:
parent
7a36967b5e
commit
e45443b3c4
@ -327,6 +327,10 @@ func (scope *EvalScope) evalReslice(node *ast.SliceExpr) (*Variable, error) {
|
||||
return nil, fmt.Errorf("second slice argument must be empty for maps")
|
||||
}
|
||||
xev.mapSkip += int(low)
|
||||
xev.loadValue()
|
||||
if xev.Unreadable != nil {
|
||||
return nil, xev.Unreadable
|
||||
}
|
||||
return xev, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("can not slice \"%s\" (type %s)", exprToString(node.X), xev.DwarfType.String())
|
||||
|
||||
@ -1113,6 +1113,7 @@ func (v *Variable) loadMap(recurseLevel int) {
|
||||
|
||||
for skip := 0; skip < v.mapSkip; skip++ {
|
||||
if ok := it.next(); !ok {
|
||||
v.Unreadable = fmt.Errorf("map index out of bounds")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -396,6 +396,7 @@ func TestEvalExpression(t *testing.T) {
|
||||
{"m2[*p1].B", false, "11", "", "int", nil},
|
||||
{"m3[as1]", false, "42", "", "int", nil},
|
||||
{"mnil[\"Malone\"]", false, "", "", "", fmt.Errorf("key not found")},
|
||||
{"m1[80:]", false, "", "", "", fmt.Errorf("map index out of bounds")},
|
||||
|
||||
// combined expressions
|
||||
{"c1.pb.a.A", true, "1", "", "int", nil},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user