From ca30bcce456d20702e3699822cd4f1c963ef1cec Mon Sep 17 00:00:00 2001 From: Zeke Lu Date: Mon, 26 Sep 2022 22:49:28 +0800 Subject: [PATCH] address review issue --- src/internal/saferio/io.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/internal/saferio/io.go b/src/internal/saferio/io.go index 8f8262e844..66cc044c74 100644 --- a/src/internal/saferio/io.go +++ b/src/internal/saferio/io.go @@ -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