1
0
mirror of https://github.com/golang/go synced 2024-09-30 02:34:40 -06:00

address review issue

This commit is contained in:
Zeke Lu 2022-09-26 22:49:28 +08:00
parent 51302b36b8
commit ca30bcce45

View File

@ -121,12 +121,11 @@ func SliceCap(v any, c uint64) int {
if typ.Kind() != reflect.Ptr {
panic("SliceCap called with non-pointer type")
}
size := typ.Elem().Size()
total := uintptr(c) * size
if size > 0 && total/size != uintptr(c) {
size := uint64(typ.Elem().Size())
if size > 0 && c > (1<<64-1)/size {
return -1
}
if total > chunk {
if c*size > chunk {
c = uint64(chunk / size)
if c == 0 {
c = 1