mirror of
https://github.com/golang/go
synced 2024-11-17 12:14:47 -07:00
runtime/metrics: fix panic in readingAllMetric example
medianBucket can return if the total is greater than thresh. However, if a histogram has no counts, total and thresh will both be zero and cause panic. Adding an equal sign to prevent the potential panic. Fixes #44148 Change-Id: Ifb8a781990f490d142ae7c035b4e01d6a07ae04d Reviewed-on: https://go-review.googlesource.com/c/go/+/290171 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
ed3e4afa12
commit
1901853098
@ -88,7 +88,7 @@ func medianBucket(h *metrics.Float64Histogram) float64 {
|
||||
total = 0
|
||||
for i, count := range h.Counts {
|
||||
total += count
|
||||
if total > thresh {
|
||||
if total >= thresh {
|
||||
return h.Buckets[i]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user