Skip to content

Commit f1d11ca

Browse files
committed
avoid panics with typelinks
1 parent 3dcbebc commit f1d11ca

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

troop_types.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,18 @@ func (t *Troop) typelinks() ([]unsafe.Pointer, [][]uint32, error) {
3636
}, false)
3737
fn := reflect.ValueOf(makeInterface(dataPtr(fn_typ), unsafe.Pointer(&pc)))
3838
out := ifaces(fn.Call(nil))
39-
return out[0].([]unsafe.Pointer), out[1].([][]uint32), nil
39+
if len(out) != 2 {
40+
return nil, nil, errs.New("wrong number of output results: %d", len(out))
41+
}
42+
sections, ok := out[0].([]unsafe.Pointer)
43+
if !ok {
44+
return nil, nil, errs.New("wrong type of sections: %T", out[0])
45+
}
46+
offsets, ok := out[1].([][]uint32)
47+
if !ok {
48+
return nil, nil, errs.New("wrong type of offsets: %T", out[1])
49+
}
50+
return sections, offsets, nil
4051
}
4152
return nil, nil, errs.New("unable to find reflect.typelinks")
4253
}

0 commit comments

Comments
 (0)