From: Julius Bünger Date: Sun, 8 Apr 2018 21:55:45 +0000 (+0200) Subject: rps profiler: prevent division by zero X-Git-Tag: v0.11.0pre66~122^2~5 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ebee6164ba4e1d50e66d0e195a33e63abac31faa;p=oweals%2Fgnunet.git rps profiler: prevent division by zero --- 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++)