[Libvirt-cim] [PATCH 10/19] Coverity: Resolve DEADCODE - octets_from_ip()

John Ferlan jferlan at redhat.com
Thu May 16 14:57:45 UTC 2013


95

(3) Event cond_at_least:
    Condition "size < 4U", taking false branch. Now the value of "size"
    is at least 4.

96              if ((s == 0) || (s[0] == '\0') || (buffer == NULL) || (size < 4))
...
106                     family = strstr(s, ":") ? AF_INET6 : AF_INET;

(1) Event assignment:
    Assigning: "n" = "(family == 10U) ? 16 : 4".

107                     n  = family == AF_INET6 ? 16 : 4;
108

(4) Event cond_at_least:
    Condition "size < n", taking false branch. Now the value of "size"
    is at least 16.

109                     if (size < n)
110                             return 0;
111
112                     if (inet_pton(family, s, &addr)) {

(2) Event intervals:
    At condition "n <= size", the value of "n" must be in one of the
    following intervals: {[4,4], [16,16]}.
(5) Event at_least:
    At condition "n <= size", the value of "size" must be at least 4.
(6) Event dead_error_condition:
    The condition "n <= size" must be true.
(7) Event dead_error_line:
    Execution cannot reach this expression "size" inside statement
    "n = ((n <= size) ? n : size);".

113                             n = n <= size ? n : size;

Resolve by removing "if (size < n) return 0;" check
---
 src/Virt_FilterEntry.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/Virt_FilterEntry.c b/src/Virt_FilterEntry.c
index 3c4a3e6..2932be2 100644
--- a/src/Virt_FilterEntry.c
+++ b/src/Virt_FilterEntry.c
@@ -106,9 +106,6 @@ static int octets_from_ip(const char * s, unsigned int *buffer,
                 family = strstr(s, ":") ? AF_INET6 : AF_INET;
                 n  = family == AF_INET6 ? 16 : 4;
 
-                if (size < n)
-                        return 0;
-
                 if (inet_pton(family, s, &addr)) {
                         n = n <= size ? n : size;
                         for (i = 0; i < n; i++)
-- 
1.8.1.4




More information about the Libvirt-cim mailing list