From da17249efd9e5c24471998360f7cbac5c08a7ef6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20B=C3=BCnger?= Date: Wed, 16 May 2018 21:32:01 +0200 Subject: [PATCH] prevent division by zero --- src/rps/test_rps.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index b433a51d4..cf38219f1 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c @@ -2180,22 +2180,25 @@ void view_update_cb (void *cls, rps_peer->index, count_peer_in_views_2 (rps_peer->index)); cumulated_view_sizes(); - to_file ("/tmp/rps/repr.txt", - "%" PRIu64 /* index */ - " %" PRIu32 /* occurrence in views */ - " %" PRIu32 /* view sizes */ - " %f" /* fraction of repr in views */ - " %f" /* average view size */ - " %f" /* prob of occurrence in view slot */ - " %f" "", /* exp frac of repr in views */ - rps_peer->index, - count_peer_in_views_2 (rps_peer->index), - view_sizes, - count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ - view_sizes / (view_size * 1.0), /* average view size */ - 1.0 /view_size, /* prob of occurrence in view slot */ - (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ - ); + if (0 != view_size) + { + to_file ("/tmp/rps/repr.txt", + "%" PRIu64 /* index */ + " %" PRIu32 /* occurrence in views */ + " %" PRIu32 /* view sizes */ + " %f" /* fraction of repr in views */ + " %f" /* average view size */ + " %f" /* prob of occurrence in view slot */ + " %f" "", /* exp frac of repr in views */ + rps_peer->index, + count_peer_in_views_2 (rps_peer->index), + view_sizes, + count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ + view_sizes / (view_size * 1.0), /* average view size */ + 1.0 /view_size, /* prob of occurrence in view slot */ + (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ + ); + } compute_probabilities (rps_peer->index); all_views_updated_cb(); } -- 2.25.1