From 1ed529825224e86f03e2083966cc21222efd8510 Mon Sep 17 00:00:00 2001 From: Teemu Toivola Date: Sat, 10 Feb 2018 00:33:10 +0200 Subject: [PATCH] avoid possible division by zero --- src/dbshow.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/dbshow.c b/src/dbshow.c index e752c28..8bdeefa 100644 --- a/src/dbshow.c +++ b/src/dbshow.c @@ -500,6 +500,7 @@ void showoneline(const interfaceinfo *interface) { struct tm *d; char daytemp[DATEBUFFLEN]; + uint64_t div; dbdatalist *datalist = NULL; dbdatalistinfo datainfo; @@ -535,7 +536,11 @@ void showoneline(const interfaceinfo *interface) printf("%"PRIu64";", datalist->rx); printf("%"PRIu64";", datalist->tx); printf("%"PRIu64";", datalist->rx+datalist->tx); - printf("%"PRIu64";", (datalist->rx+datalist->tx)/(d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600))); + div = d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600); + if (!div) { + div = 1; + } + printf("%"PRIu64";", (datalist->rx+datalist->tx)/div); } else { printf("%s;", getvalue(datalist->rx, 1, 1)); printf("%s;", getvalue(datalist->tx, 1, 1)); @@ -558,7 +563,11 @@ void showoneline(const interfaceinfo *interface) printf("%"PRIu64";", datalist->rx); printf("%"PRIu64";", datalist->tx); printf("%"PRIu64";", datalist->rx+datalist->tx); - printf("%"PRIu64";", (datalist->rx+datalist->tx)/(mosecs(datalist->timestamp, interface->updated))); + div = mosecs(datalist->timestamp, interface->updated); + if (!div) { + div = 1; + } + printf("%"PRIu64";", (datalist->rx+datalist->tx)/div); } else { printf("%s;", getvalue(datalist->rx, 1, 1)); printf("%s;", getvalue(datalist->tx, 1, 1)); -- 2.40.0