[v3,4/5] app/testpmd: fix variable use before NULL check

Message ID 20190408094640.46030-5-bruce.richardson@intel.com
State Accepted, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • some small fixes
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Bruce Richardson April 8, 2019, 9:46 a.m.
The value returned from rte_eth_dev_tx_offload_name() function is used
for string comparison before being checked for NULL. Move the NULL check
up to be done first.

Coverity issue: 279438
Fixes: c73a9071877a ("app/testpmd: add commands to test new offload API")
Cc: wei.dai@intel.com
Cc: stable@dpdk.org
Cc: Bernard Iremonger <bernard.iremonger@intel.com>
Cc: Wenzhuo Lu <wenzhuo.lu@intel.com>

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Rami Rosen <ramirose@gmail.com>
---
 app/test-pmd/cmdline.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 2ab03c111..391bc8097 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -18311,13 +18311,13 @@  search_tx_offload(const char *name)
 	single_offload = 1;
 	for (bit = 0; bit < sizeof(single_offload) * CHAR_BIT; bit++) {
 		single_name = rte_eth_dev_tx_offload_name(single_offload);
+		if (single_name == NULL)
+			break;
 		if (!strcasecmp(single_name, name)) {
 			found = 1;
 			break;
 		} else if (!strcasecmp(single_name, "UNKNOWN"))
 			break;
-		else if (single_name == NULL)
-			break;
 		single_offload <<= 1;
 	}