Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 052fcde

Browse files
cuiweixiegopherbot
authored andcommitted
internal/runtime: cleaner overflow checker
remove todo Change-Id: I4b10d7a8c26bea9296b321f53abd0330f2afc35a GitHub-Last-Rev: b939acc GitHub-Pull-Request: #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>
1 parent 3871c0d commit 052fcde

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

‎src/internal/runtime/maps/table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package maps
88
import (
99
"internal/abi"
1010
"internal/goarch"
11+
"internal/runtime/math"
1112
"unsafe"
1213
)
1314

@@ -127,8 +128,7 @@ func (t *table) maxGrowthLeft() uint16 {
127128
// single-group tables, we could fill all slots.
128129
return t.capacity - 1
129130
} else {
130-
if t.capacity*maxAvgGroupLoad < t.capacity {
131-
// TODO(prattmic): Do something cleaner.
131+
if t.capacity > math.MaxUint16/maxAvgGroupLoad {
132132
panic("overflow")
133133
}
134134
return (t.capacity * maxAvgGroupLoad) / abi.MapGroupSlots

‎src/internal/runtime/math/math.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package math
77
import "internal/goarch"
88

99
const (
10+
MaxUint16 = ^uint16(0)
1011
MaxUint32 = ^uint32(0)
1112
MaxUint64 = ^uint64(0)
1213
MaxUintptr = ^uintptr(0)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /