From 26a43982bf3b705770603828043a92663e8dc280 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 11 Jul 2018 23:59:45 +0200 Subject: [PATCH] fix div by zero --- src/core/test_core_api_reliability.c | 4 +++- src/core/test_core_quota_compliance.c | 5 +++-- src/transport/test_quota_compliance.c | 4 +++- src/transport/test_transport_api_reliability.c | 4 +++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index 4cc5b4bcd..c7c71f1f1 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ @@ -143,6 +143,8 @@ do_shutdown (void *cls) unsigned long long delta; delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; + if (0 == delta) + delta = 1; FPRINTF (stderr, "\nThroughput was %llu kb/s\n", total_bytes * 1000000LL / 1024 / delta); diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index a15105556..caff045f0 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ @@ -227,7 +227,8 @@ measurement_stop (void *cls) running = GNUNET_NO; delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; - + if (0 == delta) + delta = 1; throughput_out = total_bytes_sent * 1000000LL / delta; /* convert to bytes/s */ throughput_in = total_bytes_recv * 1000000LL / delta; /* convert to bytes/s */ diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 0ef3c864a..cd93ff855 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ @@ -65,6 +65,8 @@ report () unsigned long long datarate; delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; + if (0 == delta) + delta = 1; datarate = (total_bytes_recv * 1000 * 1000) / delta; FPRINTF (stderr, diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 86e2a7e9d..c6e77bae0 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ @@ -174,6 +174,8 @@ custom_shutdown (void *cls) /* Calculcate statistics */ delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; + if (0 == delta) + delta = 1; rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); FPRINTF (stderr, "\nThroughput was %llu KiBytes/s\n", -- 2.25.1