memif: fix coverity divide by zero 01/10001/2
authorSteven <sluong@cisco.com>
Mon, 8 Jan 2018 17:24:04 +0000 (09:24 -0800)
committerDamjan Marion <dmarion.lists@gmail.com>
Tue, 9 Jan 2018 20:20:13 +0000 (20:20 +0000)
Coverity complains about divide by zero if tx_queues gets the value of 0
from the macro vec_len(). While we don't anticipate such condition to
happen, programming errors may exist. To defend against divide by zero,
crash and burn if tx_queues gets a value of 0.

Change-Id: I65e014c07e9d4adfe119d5b373b5dc24cb818a03
Signed-off-by: Steven <sluong@cisco.com>
src/plugins/memif/device.c

index 5f67056..3809061 100644 (file)
@@ -176,6 +176,7 @@ memif_interface_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
 
   if (tx_queues < vec_len (vlib_mains))
     {
+      ASSERT (tx_queues > 0);
       qid = thread_index % tx_queues;
       clib_spinlock_lock_if_init (&mif->lockp);
     }