From ebee6164ba4e1d50e66d0e195a33e63abac31faa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20B=C3=BCnger?= Date: Sun, 8 Apr 2018 23:55:45 +0200 Subject: [PATCH] rps profiler: prevent division by zero --- src/rps/test_rps.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index 4c10133d2..00835794b 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c @@ -1994,9 +1994,17 @@ static void compute_probabilities (uint32_t peer_idx) if (0 != probs[i]) count_non_zero_prob++; } /* normalize */ - for (i = 0; i < num_peers; i++) + if (0 != count_non_zero_prob) { - probs[i] = probs[i] * (1.0 / count_non_zero_prob); + for (i = 0; i < num_peers; i++) + { + probs[i] = probs[i] * (1.0 / count_non_zero_prob); + } + } else { + for (i = 0; i < num_peers; i++) + { + probs[i] = 0; + } } /* str repr */ for (i = 0; i < num_peers; i++) -- 2.25.1