9119d9
From 7effb438a6559722feaa24501dcfbb1312e687fa Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <7effb438a6559722feaa24501dcfbb1312e687fa@dist-git>
9119d9
From: John Ferlan <jferlan@redhat.com>
9119d9
Date: Mon, 3 Nov 2014 10:00:24 -0500
9119d9
Subject: [PATCH] virnetdev: Resolve Coverity DEADCODE
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=848199
9119d9
9119d9
Coverity complains that because the for loop is from 0 to 5 (max tokens)
9119d9
and the impending switch/case statements used each of the #define values
9119d9
that the 'default' wouldn't reachable. This patch will convert the #define's
9119d9
into enum's and add the obligatory dead_error_begin marker for these type
9119d9
situations.
9119d9
9119d9
Signed-off-by: John Ferlan <jferlan@redhat.com>
9119d9
(cherry picked from commit 764deecbd9d132264b43ad405d7f87271c92f121)
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/util/virnetdev.c | 34 ++++++++++++++++++++--------------
9119d9
 1 file changed, 20 insertions(+), 14 deletions(-)
9119d9
9119d9
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
9119d9
index 381031a..147ec5b 100644
9119d9
--- a/src/util/virnetdev.c
9119d9
+++ b/src/util/virnetdev.c
9119d9
@@ -59,15 +59,19 @@ VIR_LOG_INIT("util.netdev");
9119d9
 #define PROC_NET_DEV_MCAST "/proc/net/dev_mcast"
9119d9
 #define MAX_MCAST_SIZE 50*14336
9119d9
 #define VIR_MCAST_NAME_LEN (IFNAMSIZ + 1)
9119d9
-#define VIR_MCAST_INDEX_TOKEN_IDX 0
9119d9
-#define VIR_MCAST_NAME_TOKEN_IDX 1
9119d9
-#define VIR_MCAST_USERS_TOKEN_IDX 2
9119d9
-#define VIR_MCAST_GLOBAL_TOKEN_IDX 3
9119d9
-#define VIR_MCAST_ADDR_TOKEN_IDX 4
9119d9
-#define VIR_MCAST_NUM_TOKENS 5
9119d9
 #define VIR_MCAST_TOKEN_DELIMS " \n"
9119d9
 #define VIR_MCAST_ADDR_LEN (VIR_MAC_HEXLEN + 1)
9119d9
 
9119d9
+typedef enum {
9119d9
+    VIR_MCAST_TYPE_INDEX_TOKEN,
9119d9
+    VIR_MCAST_TYPE_NAME_TOKEN,
9119d9
+    VIR_MCAST_TYPE_USERS_TOKEN,
9119d9
+    VIR_MCAST_TYPE_GLOBAL_TOKEN,
9119d9
+    VIR_MCAST_TYPE_ADDR_TOKEN,
9119d9
+
9119d9
+    VIR_MCAST_TYPE_LAST
9119d9
+} virMCastType;
9119d9
+
9119d9
 typedef struct _virNetDevMcastEntry virNetDevMcastEntry;
9119d9
 typedef virNetDevMcastEntry *virNetDevMcastEntryPtr;
9119d9
 struct _virNetDevMcastEntry  {
9119d9
@@ -2069,7 +2073,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
9119d9
     char *saveptr;
9119d9
     char *endptr;
9119d9
 
9119d9
-    for (ifindex = 0, next = buf; ifindex < VIR_MCAST_NUM_TOKENS; ifindex++,
9119d9
+    for (ifindex = 0, next = buf; ifindex < VIR_MCAST_TYPE_LAST; ifindex++,
9119d9
          next = NULL) {
9119d9
         token = strtok_r(next, VIR_MCAST_TOKEN_DELIMS, &saveptr);
9119d9
 
9119d9
@@ -2080,8 +2084,8 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
9119d9
             return -1;
9119d9
         }
9119d9
 
9119d9
-        switch (ifindex) {
9119d9
-            case VIR_MCAST_INDEX_TOKEN_IDX:
9119d9
+        switch ((virMCastType)ifindex) {
9119d9
+            case VIR_MCAST_TYPE_INDEX_TOKEN:
9119d9
                 if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
9119d9
                     virReportSystemError(EINVAL,
9119d9
                                          _("Failed to parse interface index from '%s'"),
9119d9
@@ -2091,7 +2095,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
9119d9
                 }
9119d9
                 mcast->index = num;
9119d9
                 break;
9119d9
-            case VIR_MCAST_NAME_TOKEN_IDX:
9119d9
+            case VIR_MCAST_TYPE_NAME_TOKEN:
9119d9
                 if (virStrncpy(mcast->name, token, strlen(token),
9119d9
                     VIR_MCAST_NAME_LEN) == NULL) {
9119d9
                     virReportSystemError(EINVAL,
9119d9
@@ -2100,7 +2104,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
9119d9
                     return -1;
9119d9
                 }
9119d9
                 break;
9119d9
-            case VIR_MCAST_USERS_TOKEN_IDX:
9119d9
+            case VIR_MCAST_TYPE_USERS_TOKEN:
9119d9
                 if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
9119d9
                     virReportSystemError(EINVAL,
9119d9
                                          _("Failed to parse users from '%s'"),
9119d9
@@ -2110,7 +2114,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
9119d9
                 }
9119d9
                 mcast->users = num;
9119d9
                 break;
9119d9
-            case VIR_MCAST_GLOBAL_TOKEN_IDX:
9119d9
+            case VIR_MCAST_TYPE_GLOBAL_TOKEN:
9119d9
                 if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
9119d9
                     virReportSystemError(EINVAL,
9119d9
                                          _("Failed to parse users from '%s'"),
9119d9
@@ -2120,7 +2124,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
9119d9
                 }
9119d9
                 mcast->global = num;
9119d9
                 break;
9119d9
-            case VIR_MCAST_ADDR_TOKEN_IDX:
9119d9
+            case VIR_MCAST_TYPE_ADDR_TOKEN:
9119d9
                 if (virMacAddrParseHex((const char*)token,
9119d9
                     &mcast->macaddr) < 0) {
9119d9
                     virReportSystemError(EINVAL,
9119d9
@@ -2128,7 +2132,9 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
9119d9
                                          buf);
9119d9
                 }
9119d9
                 break;
9119d9
-            default:
9119d9
+
9119d9
+            /* coverity[dead_error_begin] */
9119d9
+            case VIR_MCAST_TYPE_LAST:
9119d9
                 break;
9119d9
         }
9119d9
     }
9119d9
-- 
9119d9
2.1.3
9119d9