From 66d1776fb85530b446dcc1f68929231849a5ad44 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 8 Jul 2018 01:16:16 -0500 Subject: Fix division by zero errors and double summary in ping. --- toys/net/ping.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'toys/net') diff --git a/toys/net/ping.c b/toys/net/ping.c index 86384794..36933939 100644 --- a/toys/net/ping.c +++ b/toys/net/ping.c @@ -76,9 +76,9 @@ static void summary(int sig) if (!(toys.optflags&FLAG_q) && TT.sent && TT.sa) { printf("\n--- %s ping statistics ---\n", ntop(TT.sa)); printf("%lu packets transmitted, %lu received, %ld%% packet loss\n", - TT.sent, TT.recv, ((TT.sent-TT.recv)*100)/TT.sent); + TT.sent, TT.recv, ((TT.sent-TT.recv)*100)/(TT.sent?TT.sent:1)); printf("round-trip min/avg/max = %lu/%lu/%lu ms\n", - TT.min, TT.max, TT.fugit/TT.recv); + TT.min, TT.max, TT.fugit/(TT.recv?TT.recv:1)); } TT.sa = 0; } @@ -278,6 +278,7 @@ void ping_main(void) toys.exitval = 0; } + sigatexit(0); summary(0); if (CFG_TOYBOX_FREE) { -- cgit v1.2.3