interp: return a proper error message when indexing out of range

This helps debug issues inside interp.
This commit is contained in:
Ayke van Laethem
2024-02-27 14:11:19 +01:00
committed by Ron Evans
parent c8f77d26a8
commit 9951eb9990
2 changed files with 21 additions and 7 deletions
+3 -3
View File
@@ -517,12 +517,12 @@ func (v pointerValue) offset() uint32 {
// addOffset essentially does a GEP operation (pointer arithmetic): it adds the
// offset to the pointer. It also checks that the offset doesn't overflow the
// maximum offset size (which is 4GB).
func (v pointerValue) addOffset(offset int64) pointerValue {
func (v pointerValue) addOffset(offset int64) (pointerValue, error) {
result := pointerValue{v.pointer + uint64(offset)}
if checks && v.index() != result.index() {
panic("interp: offset out of range")
return result, fmt.Errorf("interp: offset %d out of range for object %v", offset, v)
}
return result
return result, nil
}
func (v pointerValue) len(r *runner) uint32 {