diff options
| author | cuiweixie <cuiweixie@gmail.com> | 2025-08-08 09:42:56 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-08-15 08:13:02 -0700 |
| commit | 052fcde9fdd1655f823e810a284c651b3481a433 (patch) | |
| tree | d3935623000c9c2ae6810df2995d66bc90e233b2 /src/internal/runtime | |
| parent | 3871c0d84d214bdecc370c8717c71a9a155a363f (diff) | |
| download | go-052fcde9fdd1655f823e810a284c651b3481a433.tar.xz | |
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 <mpratt@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/internal/runtime')
| -rw-r--r-- | src/internal/runtime/maps/table.go | 4 | ||||
| -rw-r--r-- | src/internal/runtime/math/math.go | 1 |
2 files changed, 3 insertions, 2 deletions
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) |
