mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
virnetdev: Resolve Coverity DEADCODE
Coverity complains that because the for loop is from 0 to 5 (max tokens) and the impending switch/case statements used each of the #define values that the 'default' wouldn't reachable. This patch will convert the #define's into enum's and add the obligatory dead_error_begin marker for these type situations. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
16d2bc8b98
commit
764deecbd9
@ -59,15 +59,19 @@ VIR_LOG_INIT("util.netdev");
|
|||||||
#define PROC_NET_DEV_MCAST "/proc/net/dev_mcast"
|
#define PROC_NET_DEV_MCAST "/proc/net/dev_mcast"
|
||||||
#define MAX_MCAST_SIZE 50*14336
|
#define MAX_MCAST_SIZE 50*14336
|
||||||
#define VIR_MCAST_NAME_LEN (IFNAMSIZ + 1)
|
#define VIR_MCAST_NAME_LEN (IFNAMSIZ + 1)
|
||||||
#define VIR_MCAST_INDEX_TOKEN_IDX 0
|
|
||||||
#define VIR_MCAST_NAME_TOKEN_IDX 1
|
|
||||||
#define VIR_MCAST_USERS_TOKEN_IDX 2
|
|
||||||
#define VIR_MCAST_GLOBAL_TOKEN_IDX 3
|
|
||||||
#define VIR_MCAST_ADDR_TOKEN_IDX 4
|
|
||||||
#define VIR_MCAST_NUM_TOKENS 5
|
|
||||||
#define VIR_MCAST_TOKEN_DELIMS " \n"
|
#define VIR_MCAST_TOKEN_DELIMS " \n"
|
||||||
#define VIR_MCAST_ADDR_LEN (VIR_MAC_HEXLEN + 1)
|
#define VIR_MCAST_ADDR_LEN (VIR_MAC_HEXLEN + 1)
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
VIR_MCAST_TYPE_INDEX_TOKEN,
|
||||||
|
VIR_MCAST_TYPE_NAME_TOKEN,
|
||||||
|
VIR_MCAST_TYPE_USERS_TOKEN,
|
||||||
|
VIR_MCAST_TYPE_GLOBAL_TOKEN,
|
||||||
|
VIR_MCAST_TYPE_ADDR_TOKEN,
|
||||||
|
|
||||||
|
VIR_MCAST_TYPE_LAST
|
||||||
|
} virMCastType;
|
||||||
|
|
||||||
typedef struct _virNetDevMcastEntry virNetDevMcastEntry;
|
typedef struct _virNetDevMcastEntry virNetDevMcastEntry;
|
||||||
typedef virNetDevMcastEntry *virNetDevMcastEntryPtr;
|
typedef virNetDevMcastEntry *virNetDevMcastEntryPtr;
|
||||||
struct _virNetDevMcastEntry {
|
struct _virNetDevMcastEntry {
|
||||||
@ -2076,7 +2080,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
|
|||||||
char *saveptr;
|
char *saveptr;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
|
||||||
for (ifindex = 0, next = buf; ifindex < VIR_MCAST_NUM_TOKENS; ifindex++,
|
for (ifindex = 0, next = buf; ifindex < VIR_MCAST_TYPE_LAST; ifindex++,
|
||||||
next = NULL) {
|
next = NULL) {
|
||||||
token = strtok_r(next, VIR_MCAST_TOKEN_DELIMS, &saveptr);
|
token = strtok_r(next, VIR_MCAST_TOKEN_DELIMS, &saveptr);
|
||||||
|
|
||||||
@ -2087,8 +2091,8 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ifindex) {
|
switch ((virMCastType)ifindex) {
|
||||||
case VIR_MCAST_INDEX_TOKEN_IDX:
|
case VIR_MCAST_TYPE_INDEX_TOKEN:
|
||||||
if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
|
if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
|
||||||
virReportSystemError(EINVAL,
|
virReportSystemError(EINVAL,
|
||||||
_("Failed to parse interface index from '%s'"),
|
_("Failed to parse interface index from '%s'"),
|
||||||
@ -2098,7 +2102,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
|
|||||||
}
|
}
|
||||||
mcast->index = num;
|
mcast->index = num;
|
||||||
break;
|
break;
|
||||||
case VIR_MCAST_NAME_TOKEN_IDX:
|
case VIR_MCAST_TYPE_NAME_TOKEN:
|
||||||
if (virStrncpy(mcast->name, token, strlen(token),
|
if (virStrncpy(mcast->name, token, strlen(token),
|
||||||
VIR_MCAST_NAME_LEN) == NULL) {
|
VIR_MCAST_NAME_LEN) == NULL) {
|
||||||
virReportSystemError(EINVAL,
|
virReportSystemError(EINVAL,
|
||||||
@ -2107,7 +2111,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VIR_MCAST_USERS_TOKEN_IDX:
|
case VIR_MCAST_TYPE_USERS_TOKEN:
|
||||||
if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
|
if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
|
||||||
virReportSystemError(EINVAL,
|
virReportSystemError(EINVAL,
|
||||||
_("Failed to parse users from '%s'"),
|
_("Failed to parse users from '%s'"),
|
||||||
@ -2117,7 +2121,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
|
|||||||
}
|
}
|
||||||
mcast->users = num;
|
mcast->users = num;
|
||||||
break;
|
break;
|
||||||
case VIR_MCAST_GLOBAL_TOKEN_IDX:
|
case VIR_MCAST_TYPE_GLOBAL_TOKEN:
|
||||||
if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
|
if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
|
||||||
virReportSystemError(EINVAL,
|
virReportSystemError(EINVAL,
|
||||||
_("Failed to parse users from '%s'"),
|
_("Failed to parse users from '%s'"),
|
||||||
@ -2127,7 +2131,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
|
|||||||
}
|
}
|
||||||
mcast->global = num;
|
mcast->global = num;
|
||||||
break;
|
break;
|
||||||
case VIR_MCAST_ADDR_TOKEN_IDX:
|
case VIR_MCAST_TYPE_ADDR_TOKEN:
|
||||||
if (virMacAddrParseHex((const char*)token,
|
if (virMacAddrParseHex((const char*)token,
|
||||||
&mcast->macaddr) < 0) {
|
&mcast->macaddr) < 0) {
|
||||||
virReportSystemError(EINVAL,
|
virReportSystemError(EINVAL,
|
||||||
@ -2135,7 +2139,9 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
|
|||||||
buf);
|
buf);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
|
/* coverity[dead_error_begin] */
|
||||||
|
case VIR_MCAST_TYPE_LAST:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user