]> Cypherpunks repositories - gostls13.git/commitdiff
all: calculate the median uniformly
authorJes Cok <xigua67damn@gmail.com>
Tue, 12 Sep 2023 13:18:33 +0000 (13:18 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 12 Sep 2023 20:16:26 +0000 (20:16 +0000)
This is a follow up of CL 526496.

Change-Id: I9f351951bf975e31befd36b9c951d195d2f8f9f7
GitHub-Last-Rev: 4307adafbffef7494d6f807b69df3e56328d6bf4
GitHub-Pull-Request: golang/go#62590
Reviewed-on: https://go-review.googlesource.com/c/go/+/527576
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/internal/godebugs/table.go
src/runtime/mranges.go
src/syscall/syscall_openbsd.go

index cc169e6661e24fff09dba385ab3a0662b36dc2dc..09d5616c9d660d7986f13b0f82083c9981e537e9 100644 (file)
@@ -55,7 +55,7 @@ func Lookup(name string) *Info {
        lo := 0
        hi := len(All)
        for lo < hi {
-               m := lo + (hi-lo)>>1
+               m := int(uint(lo+hi) >> 1)
                mid := All[m].Name
                if name == mid {
                        return &All[m]
index 4388d2608822867558654789afa710d3ab4eb057..6dd1a752473220f0221ddb74ca509aff234fab0e 100644 (file)
@@ -271,7 +271,7 @@ func (a *addrRanges) findSucc(addr uintptr) int {
        const iterMax = 8
        bot, top := 0, len(a.ranges)
        for top-bot > iterMax {
-               i := ((top - bot) / 2) + bot
+               i := int(uint(bot+top) >> 1)
                if a.ranges[i].contains(base.addr()) {
                        // a.ranges[i] contains base, so
                        // its successor is the next index.
index 5784d5c583d718934abfabaeb8cff46df33ebbd1..44bb1121ac0a2dd36f2a261014777866fc27a8a4 100644 (file)
@@ -37,7 +37,7 @@ func nametomib(name string) (mib []_C_int, err error) {
        left := 0
        right := len(sysctlMib) - 1
        for {
-               idx := left + (right-left)/2
+               idx := int(uint(left+right) >> 1)
                switch {
                case name == sysctlMib[idx].ctlname:
                        return sysctlMib[idx].ctloid, nil