VPP-189 Clean up more coverity warnings 22/2222/2
authorDave Barach <[email protected]>
Thu, 4 Aug 2016 22:58:05 +0000 (18:58 -0400)
committerFlorin Coras <[email protected]>
Fri, 5 Aug 2016 13:21:59 +0000 (13:21 +0000)
Change-Id: I1b971ab326dc334a4743fd7d4184cef106b0523d
Signed-off-by: Dave Barach <[email protected]>
svm/ssvm.c
vnet/vnet/ip/ip4_mtrie.c
vnet/vnet/ip/ip6_neighbor.c
vppinfra/vppinfra/elf.c
vppinfra/vppinfra/phash.c

index 5db1423..337840f 100644 (file)
@@ -43,7 +43,13 @@ ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
       return SSVM_API_ERROR_CREATE_FAILURE;
     }
 
-  lseek (ssvm_fd, ssvm->ssvm_size, SEEK_SET);
+  if (lseek (ssvm_fd, ssvm->ssvm_size, SEEK_SET) < 0)
+    {
+      clib_unix_warning ("lseek");
+      close (ssvm_fd);
+      return SSVM_API_ERROR_SET_SIZE;
+    }
+      
   if (write (ssvm_fd, &junk, 1) != 1)
     {
       clib_unix_warning ("set ssvm size");
index 461cd64..0badde7 100644 (file)
@@ -436,10 +436,26 @@ maybe_remap_leaf (ip_lookup_main_t * lm, ip4_fib_mtrie_leaf_t * p)
       if (m)
        {
          was_remapped_to_empty_leaf = m == ~0;
+
+          /*
+           * The intent of the original form - which dates to 2013 or
+           * earlier - is not obvious. Here's the original:
+           * 
+           * if (was_remapped_to_empty_leaf)
+           *   p[0] = (was_remapped_to_empty_leaf
+           *           ? IP4_FIB_MTRIE_LEAF_EMPTY
+           *           : ip4_fib_mtrie_leaf_set_adj_index (m - 1));
+           *
+           * Notice the outer "if (was_remapped_to_empty_leaf)"
+           * means that p[0] is always set to IP4_FIB_MTRIE_LEAF_EMPTY,
+           * and is otherwise left intact.
+           * 
+           * It seems unlikely that the adjacency mapping scheme
+           * works in detail. Coverity correctly complains that the 
+           * else-case of the original ternary expression is dead code.
+           */
          if (was_remapped_to_empty_leaf)
-           p[0] = (was_remapped_to_empty_leaf
-                   ? IP4_FIB_MTRIE_LEAF_EMPTY
-                   : ip4_fib_mtrie_leaf_set_adj_index (m - 1));
+            p[0] = IP4_FIB_MTRIE_LEAF_EMPTY;
        }
     }
   return was_remapped_to_empty_leaf;
index 888baff..2593cb4 100644 (file)
@@ -394,7 +394,13 @@ vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
       existing_adj->arp.next_hop.ip6.as_u64[1] == a->as_u64[1])
   {
     u32 * ai;
-    u32 * adjs = vec_dup(n->adjacencies);
+    u32 * adjs = 0;
+    
+    if (n)
+      adjs = vec_dup(n->adjacencies);
+    else
+      clib_warning ("ip6 neighbor n not set");
+    
     /* Update all adj assigned to this arp entry */
     vec_foreach(ai, adjs)
     {
index 8a09cd4..7fe3048 100644 (file)
@@ -1106,6 +1106,8 @@ static void byte_swap_verneed (elf_main_t * em,
   clib_bitmap_free (entries_swapped);
 }
 
+static void
+set_dynamic_verneed (elf_main_t * em) __attribute__((unused));
 static void
 set_dynamic_verneed (elf_main_t * em)
 {
@@ -1122,6 +1124,8 @@ set_dynamic_verneed (elf_main_t * em)
     vec_free (vus);
 }
 
+static void
+set_symbol_table (elf_main_t * em, u32 table_index) __attribute__((unused));
 static void
 set_symbol_table (elf_main_t * em, u32 table_index)
 {
@@ -1375,12 +1379,16 @@ static u32 string_table_add_name (string_table_builder_t * b, u8 * n)
   return i;
 }
 
+static u32 string_table_add_name_index (string_table_builder_t * b, u32 index)
+    __attribute__((unused));
 static u32 string_table_add_name_index (string_table_builder_t * b, u32 index)
 {
   u8 * n = b->old_table + index;
   return string_table_add_name (b, n);
 }
 
+static void string_table_init (string_table_builder_t * b, u8 * old_table)
+    __attribute__((unused));
 static void string_table_init (string_table_builder_t * b, u8 * old_table)
 {
   memset (b, 0, sizeof (b[0]));
@@ -1388,6 +1396,8 @@ static void string_table_init (string_table_builder_t * b, u8 * old_table)
   b->hash = hash_create_string (0, sizeof (uword));
 }
 
+static u8 * string_table_done (string_table_builder_t * b)
+    __attribute__((unused));
 static u8 * string_table_done (string_table_builder_t * b)
 {
   hash_free (b->hash);
@@ -1400,6 +1410,8 @@ static void layout_sections (elf_main_t * em)
   u32 n_sections_with_changed_exec_address = 0;
   u32 * deferred_symbol_and_string_sections = 0;
   u32 n_deleted_sections = 0;
+  /* note: rebuild is always zero. Intent lost in the sands of time */
+#if 0 
   int rebuild = 0;
 
   /* Re-build section string table (sections may have been deleted). */
@@ -1498,6 +1510,7 @@ static void layout_sections (elf_main_t * em)
       vec_free (s->contents);
       s->contents = string_table_done (&b);
     }
+#endif /* dead code */
 
   /* Figure file offsets and exec addresses for sections. */
   {
@@ -1613,8 +1626,10 @@ static void layout_sections (elf_main_t * em)
 
   /* Update dynamic entries now that sections have been assigned
      possibly new addresses. */
+#if 0
   if (rebuild)
     elf_set_dynamic_entries (em);
+#endif
 
   /* Update segments for changed section addresses. */
   {
index c883fac..a104e64 100644 (file)
@@ -662,7 +662,12 @@ static void guess_initial_parameters (phash_main_t * pm)
          a_max = 1;
          b_max = 1;
        case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
-         a_max = is_minimal ? s_max / 2 : s_max;
+          /* 
+           * Was: a_max = is_minimal ? s_max / 2 : s_max;
+           * However, we know that is_minimal must be true, so the
+           * if-arm of the ternary expression is always executed.
+           */
+         a_max = s_max/2;
          b_max = s_max/2;
          break;
        case 9: case 10: case 11: case 12: case 13: