From 5955a03e9c22c56fa3d174e95031d74e2cf3adde Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Sat, 7 Oct 2023 16:18:16 +0000 Subject: [PATCH] reflect: compute the median h uniformly Like sort.Search, use "h := int(uint(i+j) >> 1)" to compute the median h. Change-Id: I62c1e67533657e2b56af872676e5dc4ed4d49c55 GitHub-Last-Rev: cbfba7ee9ab0a0bda371db3ad5e8cc4d5ea91579 GitHub-Pull-Request: golang/go#63439 Reviewed-on: https://go-review.googlesource.com/c/go/+/533595 Reviewed-by: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI --- src/reflect/type.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reflect/type.go b/src/reflect/type.go index d6744c2898..a35898547a 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -1539,7 +1539,7 @@ func typesByString(s string) []*abi.Type { // This is a copy of sort.Search, with f(h) replaced by (*typ[h].String() >= s). i, j := 0, len(offs) for i < j { - h := i + (j-i)>>1 // avoid overflow when computing h + h := int(uint(i+j) >> 1) // avoid overflow when computing h // i ≤ h < j if !(stringFor(rtypeOff(section, offs[h])) >= s) { i = h + 1 // preserves f(i-1) == false