render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 7effb438a6559722feaa24501dcfbb1312e687fa Mon Sep 17 00:00:00 2001
Message-Id: <7effb438a6559722feaa24501dcfbb1312e687fa@dist-git>
From: John Ferlan <jferlan@redhat.com>
Date: Mon, 3 Nov 2014 10:00:24 -0500
Subject: [PATCH] virnetdev: Resolve Coverity DEADCODE

https://bugzilla.redhat.com/show_bug.cgi?id=848199

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>
(cherry picked from commit 764deecbd9d132264b43ad405d7f87271c92f121)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/util/virnetdev.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 381031a..147ec5b 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -59,15 +59,19 @@ VIR_LOG_INIT("util.netdev");
 #define PROC_NET_DEV_MCAST "/proc/net/dev_mcast"
 #define MAX_MCAST_SIZE 50*14336
 #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_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 virNetDevMcastEntry *virNetDevMcastEntryPtr;
 struct _virNetDevMcastEntry  {
@@ -2069,7 +2073,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
     char *saveptr;
     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) {
         token = strtok_r(next, VIR_MCAST_TOKEN_DELIMS, &saveptr);
 
@@ -2080,8 +2084,8 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
             return -1;
         }
 
-        switch (ifindex) {
-            case VIR_MCAST_INDEX_TOKEN_IDX:
+        switch ((virMCastType)ifindex) {
+            case VIR_MCAST_TYPE_INDEX_TOKEN:
                 if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
                     virReportSystemError(EINVAL,
                                          _("Failed to parse interface index from '%s'"),
@@ -2091,7 +2095,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
                 }
                 mcast->index = num;
                 break;
-            case VIR_MCAST_NAME_TOKEN_IDX:
+            case VIR_MCAST_TYPE_NAME_TOKEN:
                 if (virStrncpy(mcast->name, token, strlen(token),
                     VIR_MCAST_NAME_LEN) == NULL) {
                     virReportSystemError(EINVAL,
@@ -2100,7 +2104,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
                     return -1;
                 }
                 break;
-            case VIR_MCAST_USERS_TOKEN_IDX:
+            case VIR_MCAST_TYPE_USERS_TOKEN:
                 if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
                     virReportSystemError(EINVAL,
                                          _("Failed to parse users from '%s'"),
@@ -2110,7 +2114,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
                 }
                 mcast->users = num;
                 break;
-            case VIR_MCAST_GLOBAL_TOKEN_IDX:
+            case VIR_MCAST_TYPE_GLOBAL_TOKEN:
                 if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
                     virReportSystemError(EINVAL,
                                          _("Failed to parse users from '%s'"),
@@ -2120,7 +2124,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
                 }
                 mcast->global = num;
                 break;
-            case VIR_MCAST_ADDR_TOKEN_IDX:
+            case VIR_MCAST_TYPE_ADDR_TOKEN:
                 if (virMacAddrParseHex((const char*)token,
                     &mcast->macaddr) < 0) {
                     virReportSystemError(EINVAL,
@@ -2128,7 +2132,9 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
                                          buf);
                 }
                 break;
-            default:
+
+            /* coverity[dead_error_begin] */
+            case VIR_MCAST_TYPE_LAST:
                 break;
         }
     }
-- 
2.1.3