diff --git a/src/internal/runtime/maps/table.go b/src/internal/runtime/maps/table.go index d4b9276b57078f..480d12df2e2f73 100644 --- a/src/internal/runtime/maps/table.go +++ b/src/internal/runtime/maps/table.go @@ -8,6 +8,7 @@ package maps import ( "internal/abi" "internal/goarch" + "internal/runtime/math" "unsafe" ) @@ -127,8 +128,7 @@ func (t *table) maxGrowthLeft() uint16 { // single-group tables, we could fill all slots. return t.capacity - 1 } else { - if t.capacity*maxAvgGroupLoad < t.capacity { - // TODO(prattmic): Do something cleaner. + if t.capacity > math.MaxUint16/maxAvgGroupLoad { panic("overflow") } return (t.capacity * maxAvgGroupLoad) / abi.MapGroupSlots diff --git a/src/internal/runtime/math/math.go b/src/internal/runtime/math/math.go index 7b616cff797740..0af5aa3f7610d8 100644 --- a/src/internal/runtime/math/math.go +++ b/src/internal/runtime/math/math.go @@ -7,6 +7,7 @@ package math import "internal/goarch" const ( + MaxUint16 = ^uint16(0) MaxUint32 = ^uint32(0) MaxUint64 = ^uint64(0) MaxUintptr = ^uintptr(0)