From cbfba7ee9ab0a0bda371db3ad5e8cc4d5ea91579 Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Sun, 8 Oct 2023 00:02:10 +0800 Subject: [PATCH] reflect: compute the median h uniformly Like sort.Search, use "h := int(uint(i+j) >> 1)" style code to compute the median h. --- 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 d6744c2898f..a35898547a7 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