From 76070a7647b9c8b9d15a914b255298bf1b6b83b6 Mon Sep 17 00:00:00 2001 From: gatecat Date: Sat, 10 Jul 2021 23:44:21 +0100 Subject: timing: Fix out-of-bounds histogram bins in all cases Signed-off-by: gatecat --- common/timing.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/timing.cc b/common/timing.cc index 30054e83..6a91b6e5 100644 --- a/common/timing.cc +++ b/common/timing.cc @@ -1363,7 +1363,12 @@ void timing_analysis(Context *ctx, bool print_histogram, bool print_fmax, bool p std::vector bins(num_bins); unsigned max_freq = 0; for (const auto &i : slack_histogram) { - auto &bin = bins[(i.first - min_slack) / bin_size]; + int bin_idx = int((i.first - min_slack) / bin_size); + if (bin_idx < 0) + bin_idx = 0; + else if (bin_idx >= int(num_bins)) + bin_idx = num_bins - 1; + auto &bin = bins.at(bin_idx); bin += i.second; max_freq = std::max(max_freq, bin); } -- cgit v1.2.3