summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-04-24 11:46:01 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-04-24 12:06:22 +0200
commit3261e9cf14a8a80b9f524009502edf1ccd8da5eb (patch)
tree1271b84511a4afd422087bfcb04d208daacd1f51
parent87650476c4a2da66e8641e04566655b85f63bb43 (diff)
statement: Fix get_rate() for zero byte_rate
The algorithm didn't detect whether given byte_rate was zero, pointlessly iterating through data units. Make it exit early in this case. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/statement.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/statement.c b/src/statement.c
index f81e0123..fccf71c1 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -313,6 +313,11 @@ const char *get_rate(uint64_t byte_rate, uint64_t *rate)
{
int i;
+ if (!byte_rate) {
+ *rate = 0;
+ return data_unit[0];
+ }
+
for (i = 0; data_unit[i + 1] != NULL; i++) {
if (byte_rate % 1024)
break;