From 3e43647cd6f7c1e88fd7f15668c003f2e570f611 Mon Sep 17 00:00:00 2001 From: Vladimir Medvedkin Date: Fri, 1 Nov 2019 11:38:34 +0000 Subject: [PATCH 1/1] app/test-sad: add sanity checks 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. Fixes: 908be0651a5a ("app/test-sad: add test application for IPsec SAD") Signed-off-by: Vladimir Medvedkin Acked-by: Konstantin Ananyev --- 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 22e10cbe66..b01e84c570 100644 --- a/app/test-sad/main.c +++ b/app/test-sad/main.c @@ -518,6 +518,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++) @@ -533,6 +536,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.20.1