diff options
author | Changkun Ou <hi@changkun.de> | 2021-02-07 17:31:12 +0100 |
---|---|---|
committer | Michael Knyszek <mknyszek@google.com> | 2021-02-08 16:09:01 +0000 |
commit | 1901853098bbe25a1bbedc0ee53c6658d754151e (patch) | |
tree | 6d65563dc96a326d84add9d27855c932fa2dbcdf | |
parent | ed3e4afa12d655a0c5606bcf3dd4e1cdadcb1476 (diff) | |
download | go-1901853098bbe25a1bbedc0ee53c6658d754151e.tar.gz go-1901853098bbe25a1bbedc0ee53c6658d754151e.zip |
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>
-rw-r--r-- | src/runtime/metrics/example_test.go | 2 |
1 files changed, 1 insertions, 1 deletions
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] } } |