From: Changkun Ou Date: Sun, 7 Feb 2021 16:31:12 +0000 (+0100) Subject: runtime/metrics: fix panic in readingAllMetric example X-Git-Tag: go1.16~1^2~22 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1901853098bbe25a1bbedc0ee53c6658d754151e;p=gostls13.git 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 Reviewed-by: Michael Knyszek Run-TryBot: Michael Knyszek TryBot-Result: Go Bot --- diff --git a/src/runtime/metrics/example_test.go b/src/runtime/metrics/example_test.go index cade0c38bf..624d9d8a6b 100644 --- a/src/runtime/metrics/example_test.go +++ b/src/runtime/metrics/example_test.go @@ -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] } }