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")
|
return nil, fmt.Errorf("second slice argument must be empty for maps")
|
||||||
}
|
}
|
||||||
xev.mapSkip += int(low)
|
xev.mapSkip += int(low)
|
||||||
|
xev.loadValue()
|
||||||
|
if xev.Unreadable != nil {
|
||||||
|
return nil, xev.Unreadable
|
||||||
|
}
|
||||||
return xev, nil
|
return xev, nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("can not slice \"%s\" (type %s)", exprToString(node.X), xev.DwarfType.String())
|
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++ {
|
for skip := 0; skip < v.mapSkip; skip++ {
|
||||||
if ok := it.next(); !ok {
|
if ok := it.next(); !ok {
|
||||||
|
v.Unreadable = fmt.Errorf("map index out of bounds")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -396,6 +396,7 @@ func TestEvalExpression(t *testing.T) {
|
|||||||
{"m2[*p1].B", false, "11", "", "int", nil},
|
{"m2[*p1].B", false, "11", "", "int", nil},
|
||||||
{"m3[as1]", false, "42", "", "int", nil},
|
{"m3[as1]", false, "42", "", "int", nil},
|
||||||
{"mnil[\"Malone\"]", false, "", "", "", fmt.Errorf("key not found")},
|
{"mnil[\"Malone\"]", false, "", "", "", fmt.Errorf("key not found")},
|
||||||
|
{"m1[80:]", false, "", "", "", fmt.Errorf("map index out of bounds")},
|
||||||
|
|
||||||
// combined expressions
|
// combined expressions
|
||||||
{"c1.pb.a.A", true, "1", "", "int", nil},
|
{"c1.pb.a.A", true, "1", "", "int", nil},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user