From: cuiweixie Date: Fri, 8 Aug 2025 09:42:56 +0000 (+0000) Subject: internal/runtime: cleaner overflow checker X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=052fcde9fdd1655f823e810a284c651b3481a433;p=gostls13.git internal/runtime: cleaner overflow checker remove todo Change-Id: I4b10d7a8c26bea9296b321f53abd0330f2afc35a GitHub-Last-Rev: b939acc2873a02687cdafc84894ab9a712d13a98 GitHub-Pull-Request: golang/go#74943 Reviewed-on: https://go-review.googlesource.com/c/go/+/694236 Auto-Submit: Michael Pratt Reviewed-by: David Chase LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt --- diff --git a/src/internal/runtime/maps/table.go b/src/internal/runtime/maps/table.go index 7e2c6e31bc..49f392b8ae 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 7b616cff79..0af5aa3f76 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)