Fix coverity warnings, VPP-608 58/4758/2
authorDave Barach <dave@barachs.net>
Wed, 18 Jan 2017 15:23:22 +0000 (10:23 -0500)
committerDave Barach <dave@barachs.net>
Wed, 18 Jan 2017 15:32:15 +0000 (10:32 -0500)
Change-Id: Ib0144ba3a9a09971d3946c932e8fed6d5c1ad278
Signed-off-by: Dave Barach <dave@barachs.net>
src/plugins/snat/in2out.c
src/plugins/snat/out2in.c
src/vnet/devices/virtio/vhost-user.c
src/vnet/unix/tapcli.c
src/vpp/api/api_main.c
src/vppinfra/bihash_template.c

index 76a6a12..ba752cf 100644 (file)
@@ -1232,8 +1232,12 @@ snat_in2out_worker_handoff_fn (vlib_main_t * vm,
       if (clib_bihash_search_8_8 (&sm->worker_by_in, &kv0, &value0))
         {
           /* No, assign next available worker (RR) */
-          next_worker_index = sm->first_worker_index +
-            sm->workers[sm->next_worker++ % vec_len (sm->workers)];
+          next_worker_index = sm->first_worker_index;
+          if (vec_len (sm->workers))
+            {
+              next_worker_index += 
+                sm->workers[sm->next_worker++ % _vec_len (sm->workers)];
+            }
 
           /* add non-traslated packets worker lookup */
           kv0.value = next_worker_index;
index f132973..855e9ef 100644 (file)
@@ -901,8 +901,12 @@ snat_out2in_worker_handoff_fn (vlib_main_t * vm,
           if (clib_bihash_search_8_8 (&sm->worker_by_out, &kv0, &value0))
             {
               /* No, assign next available worker (RR) */
-              next_worker_index = sm->first_worker_index +
-                sm->workers[sm->next_worker++ % vec_len (sm->workers)];
+              next_worker_index = sm->first_worker_index;
+              if (vec_len (sm->workers))
+                {
+                  next_worker_index += 
+                    sm->workers[sm->next_worker++ % _vec_len (sm->workers)];
+                }
             }
           else
             {
index 9a7c1dc..ac14286 100644 (file)
@@ -2326,12 +2326,16 @@ vhost_user_process (vlib_main_t * vm,
                           sizeof (sun.sun_path) - 1);
 
                  /* Avoid hanging VPP if the other end does not accept */
-                 fcntl(sockfd, F_SETFL, O_NONBLOCK);
+                 if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0)
+                      clib_unix_warning ("fcntl");
+
                  if (connect (sockfd, (struct sockaddr *) &sun,
                               sizeof (struct sockaddr_un)) == 0)
                    {
                      /* Set the socket to blocking as it was before */
-                     fcntl(sockfd, F_SETFL, 0);
+                      if (fcntl(sockfd, F_SETFL, 0) < 0)
+                        clib_unix_warning ("fcntl2");
+
                      vui->sock_errno = 0;
                      template.file_descriptor = sockfd;
                      template.private_data =
index 2d3082c..e9dbf72 100644 (file)
@@ -899,8 +899,9 @@ int vnet_tap_connect (vlib_main_t * vm, vnet_tap_connect_args_t *ap)
       /* ip4: mask defaults to /24 */
       u32 mask = clib_host_to_net_u32 (0xFFFFFF00);
 
+      memset(&sin, 0, sizeof(sin));
       sin.sin_family = AF_INET;
-      sin.sin_port = 0;
+      /* sin.sin_port = 0; */
       sin.sin_addr.s_addr = ap->ip4_address->as_u32;
       memcpy (&ifr.ifr_ifru.ifru_addr, &sin, sizeof (sin));
 
@@ -1294,7 +1295,7 @@ tap_connect_command_fn (vlib_main_t * vm,
                 unformat_input_t * input,
                 vlib_cli_command_t * cmd)
 {
-  u8 * intfc_name;
+  u8 * intfc_name = 0;
   unformat_input_t _line_input, *line_input = &_line_input;
   vnet_tap_connect_args_t _a, *ap= &_a;
   tapcli_main_t * tm = &tapcli_main;
index db53206..fd6998f 100644 (file)
@@ -139,11 +139,11 @@ api_command_fn (vlib_main_t * vm,
                                "%s error: %U\n", cmdp,
                                format_api_error, vam, rv);
 
-      if (vam->regenerate_interface_table)
-       {
-         vam->regenerate_interface_table = 0;
-         api_sw_interface_dump (vam);
-       }
+    }
+  if (vam->regenerate_interface_table)
+    {
+      vam->regenerate_interface_table = 0;
+      api_sw_interface_dump (vam);
     }
   unformat_free (vam->input);
   return 0;
index 7c817a2..d8b97b5 100644 (file)
@@ -199,7 +199,7 @@ BV (split_and_rehash_linear)
       /* Find a free slot in the new linear scan bucket */
       for (; j < new_length; j++)
        {
-         /* Old value in use? Forget it. */
+         /* Old value not in use? Forget it. */
          if (BV (clib_bihash_is_free) (&(old_values->kvp[i])))
            goto doublebreak;
 
@@ -212,11 +212,12 @@ BV (split_and_rehash_linear)
              j++;
              goto doublebreak;
            }
-         /* This should never happen... */
-         clib_warning ("BUG: linear rehash failed!");
-         BV (value_free) (h, new_values);
-         return 0;
        }
+      /* This should never happen... */
+      clib_warning ("BUG: linear rehash failed!");
+      BV (value_free) (h, new_values);
+      return 0;
+
     doublebreak:;
     }
   return new_values;