From 8c8ebf45035cd37decd6ab1ba0ddb469866c33db Mon Sep 17 00:00:00 2001 From: zhanghongyu Date: Thu, 28 Apr 2022 22:51:22 +0800 Subject: [PATCH] wapi: fix coverity warning Signed-off-by: zhanghongyu --- wireless/wapi/src/network.c | 1 + wireless/wapi/src/util.c | 4 ++-- wireless/wapi/src/wireless.c | 30 ++++++++++++++---------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/wireless/wapi/src/network.c b/wireless/wapi/src/network.c index cd0d017fd..7a4141ef9 100644 --- a/wireless/wapi/src/network.c +++ b/wireless/wapi/src/network.c @@ -90,6 +90,7 @@ static int wapi_set_addr(int sock, FAR const char *ifname, int cmd, WAPI_VALIDATE_PTR(addr); sin.sin_family = AF_INET; + sin.sin_port = 0; memcpy(&sin.sin_addr, addr, sizeof(struct in_addr)); memcpy(&ifr.ifr_addr, &sin, sizeof(struct sockaddr_in)); strlcpy(ifr.ifr_name, ifname, IFNAMSIZ); diff --git a/wireless/wapi/src/util.c b/wireless/wapi/src/util.c index 10935a588..4f1022499 100644 --- a/wireless/wapi/src/util.c +++ b/wireless/wapi/src/util.c @@ -114,7 +114,7 @@ errout: free(buf); } - if (fd > 0) + if (fd >= 0) { close(fd); } @@ -512,7 +512,7 @@ errout: free(buf); } - if (fd > 0) + if (fd >= 0) { close(fd); } diff --git a/wireless/wapi/src/wireless.c b/wireless/wapi/src/wireless.c index f30379931..c4a61cf1b 100644 --- a/wireless/wapi/src/wireless.c +++ b/wireless/wapi/src/wireless.c @@ -1068,23 +1068,21 @@ int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power, /* Get flag. */ - if (IW_TXPOW_DBM == (wrq.u.txpower.flags & IW_TXPOW_DBM)) + switch (wrq.u.txpower.flags & IW_TXPOW_TYPE) { - *flag = WAPI_TXPOWER_DBM; - } - else if (IW_TXPOW_MWATT == (wrq.u.txpower.flags & IW_TXPOW_MWATT)) - { - *flag = WAPI_TXPOWER_MWATT; - } - else if (IW_TXPOW_RELATIVE == - (wrq.u.txpower.flags & IW_TXPOW_RELATIVE)) - { - *flag = WAPI_TXPOWER_RELATIVE; - } - else - { - WAPI_ERROR("ERROR: Unknown flag: %d\n", wrq.u.txpower.flags); - return -1; + case IW_TXPOW_DBM: + *flag = WAPI_TXPOWER_DBM; + break; + case IW_TXPOW_MWATT: + *flag = WAPI_TXPOWER_MWATT; + break; + case IW_TXPOW_RELATIVE: + *flag = WAPI_TXPOWER_RELATIVE; + break; + + default: + WAPI_ERROR("ERROR: Unknown flag: %d\n", wrq.u.txpower.flags); + return -1; } /* Get power. */