From f74221b3a8196bab5b921f9f32eae053a53a13fa Mon Sep 17 00:00:00 2001 From: amitkuma Date: Thu, 24 Aug 2017 23:32:46 +0530 Subject: [PATCH] test: Check to avoid divide by zero Fixes the coverity issue: ** 1219467 Division or modulo by zero CID 1219467 (#1 of 1): Division or modulo by zero (DIVIDE_BY_ZERO) 74. divide_by_zero: In expression 100 / atoi(args[i + 1U]), division by expression atoi(args[i + 1U]) which may be zero has undefined behavior. Signed-off-by: Amit Kumar amitkuma@redhat.com --- src/test/kv_store_bench.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/kv_store_bench.cc b/src/test/kv_store_bench.cc index 3cdc7cfe01a7..b36a088dfd6e 100644 --- a/src/test/kv_store_bench.cc +++ b/src/test/kv_store_bench.cc @@ -115,7 +115,9 @@ int KvStoreBench::setup(int argc, const char** argv) { } else if (strcmp(args[i], "--cache-size") == 0) { cache_size = atoi(args[i+1]); } else if (strcmp(args[i], "--cache-refresh") == 0) { - cache_refresh = 100 / atoi(args[i+1]); + auto temp = atoi(args[i+1]); + assert (temp != 0); + cache_refresh = 100 / temp; } else if (strcmp(args[i], "-t") == 0) { max_ops_in_flight = atoi(args[i+1]); } else if (strcmp(args[i], "--clients") == 0) { -- 2.47.3