From f3f7da624de546c8f4e6b236d364377b19c49d78 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 2 Feb 2018 16:05:06 +0000 Subject: [PATCH] perf_timer: rewrite to make it clear there is no division by zero It could have happened if epee::misc_utils::get_ns_count is buggy, at a push Coverity 182561 --- src/common/perf_timer.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/common/perf_timer.cpp b/src/common/perf_timer.cpp index 41e23130d..16abdfd99 100644 --- a/src/common/perf_timer.cpp +++ b/src/common/perf_timer.cpp @@ -49,16 +49,15 @@ namespace #ifdef __x86_64__ uint64_t get_ticks_per_ns() { - uint64_t t0 = epee::misc_utils::get_ns_count(); + uint64_t t0 = epee::misc_utils::get_ns_count(), t1; uint64_t r0 = get_tick_count(); while (1) { - uint64_t t = epee::misc_utils::get_ns_count(); - if (t - t0 > 1*1000000000) break; // work one second + t1 = epee::misc_utils::get_ns_count(); + if (t1 - t0 > 1*1000000000) break; // work one second } - uint64_t t1 = epee::misc_utils::get_ns_count(); uint64_t r1 = get_tick_count(); uint64_t tpns256 = 256 * (r1 - r0) / (t1 - t0); return tpns256 ? tpns256 : 1;