]> Cypherpunks repositories - gostls13.git/commitdiff
internal/runtime: cleaner overflow checker
authorcuiweixie <cuiweixie@gmail.com>
Fri, 8 Aug 2025 09:42:56 +0000 (09:42 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 15 Aug 2025 15:13:02 +0000 (08:13 -0700)
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>
src/internal/runtime/maps/table.go
src/internal/runtime/math/math.go

index 7e2c6e31bcaa1ec1f92888cb14a7814aa60c1183..49f392b8aee1d42c4dfe0b3571c8b17d5bd3241e 100644 (file)
@@ -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
index 7b616cff797740b1055dfef1a74da55f493810fa..0af5aa3f7610d803f1c333b66b9dc142a7712a89 100644 (file)
@@ -7,6 +7,7 @@ package math
 import "internal/goarch"
 
 const (
+       MaxUint16  = ^uint16(0)
        MaxUint32  = ^uint32(0)
        MaxUint64  = ^uint64(0)
        MaxUintptr = ^uintptr(0)