[dpdk-dev] [PATCH] app: add few sanity checks in test-sad app

Vladimir Medvedkin vladimir.medvedkin at intel.com
Fri Nov 1 12:38:34 CET 2019


Coverity reported about two division by zero:
*** CID 350344:  Incorrect expression  (DIVIDE_BY_ZERO)
Although in fact these dividers will never be equal to 0,
adding explicit checks in lookup() to make coverity happy
will not affect the execution speed.

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin at intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev at intel.com>
---
 app/test-sad/main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/app/test-sad/main.c b/app/test-sad/main.c
index bd05638..e61e33f 100644
--- a/app/test-sad/main.c
+++ b/app/test-sad/main.c
@@ -519,6 +519,9 @@ lookup(void *arg)
 	uint32_t burst_sz;
 	struct rte_ipsec_sad *sad = arg;
 
+	if (config.nb_tuples == 0)
+		return 0;
+
 	burst_sz = RTE_MIN(config.burst_sz, config.nb_tuples);
 	for (i = 0; i < config.nb_tuples; i += burst_sz) {
 		for (j = 0; j < burst_sz; j++)
@@ -534,6 +537,7 @@ lookup(void *arg)
 				print_result(keys[j], vals[j]);
 		}
 	}
+	acc = (acc == 0) ? UINT64_MAX : acc;
 	printf("Average lookup cycles %.2Lf, lookups/sec: %.2Lf\n",
 		(long double)acc / config.nb_tuples,
 		(long double)config.nb_tuples * rte_get_tsc_hz() / acc);
-- 
2.7.4



More information about the dev mailing list