vpp-189 Clean up more coverity warnings

Time to make the donuts

Change-Id: I528937800f7daefce19723dda0216e58d857942c
Signed-off-by: Dave Barach <dave@barachs.net>
diff --git a/vppinfra/tools/elftool.c b/vppinfra/tools/elftool.c
index f5d70b5..d9d3704 100644
--- a/vppinfra/tools/elftool.c
+++ b/vppinfra/tools/elftool.c
@@ -358,10 +358,12 @@
     }
 
  done:
-  if (mmap_length > 0)
+  if (mmap_length > 0 && idp)
     munmap (idp, mmap_length);
-  close (ifd);
-  close (ofd);
+  if (ifd >= 0)
+    close (ifd);
+  if (ofd >= 0)
+    close (ofd);
   return error;
 }
 
@@ -408,7 +410,10 @@
     }
 
   if (! tm->input_file)
-    clib_error ("no input file");
+    {
+      error = clib_error_return (0, "no input file");
+      goto done;
+    }
 
   /* Do the typical case a stone-simple way... */
   if (tm->quiet && tm->set_interpreter && tm->set_rpath && tm->output_file)
diff --git a/vppinfra/vppinfra/asm_x86.c b/vppinfra/vppinfra/asm_x86.c
index d89739c..16e41c2 100644
--- a/vppinfra/vppinfra/asm_x86.c
+++ b/vppinfra/vppinfra/asm_x86.c
@@ -1736,6 +1736,7 @@
     {
     default:
       ASSERT (0);
+      break;
 
     case 'x':
       ASSERT (reg < 16);
@@ -1816,6 +1817,7 @@
     /* Memory or reg field from modrm byte. */
     case 'M':
       ASSERT (p->flags & X86_INSN_IS_ADDRESS);
+      /* FALLTHROUGH */
     case 'E':
       if (p->flags & X86_INSN_IS_ADDRESS)
 	s = format (s, "%U", format_x86_mem_operand, p);
@@ -1836,7 +1838,7 @@
     case 'I':
       {
 	u32 l = x86_insn_log2_immediate_bytes (p, insn);
-	i64 mask = pow2_mask (8 << l);
+	i64 mask = pow2_mask (8ULL << l);
 	s = format (s, "$0x%Lx", p->immediate & mask);
       }
       break;
diff --git a/vppinfra/vppinfra/bitmap.h b/vppinfra/vppinfra/bitmap.h
index 35de1b4..17b72ac 100644
--- a/vppinfra/vppinfra/bitmap.h
+++ b/vppinfra/vppinfra/bitmap.h
@@ -196,7 +196,7 @@
   uword i0, i1, result;
   uword l = vec_len (bitmap);
 
-  ASSERT (n_bits >= 0 && n_bits <= BITS (result));
+  ASSERT (n_bits <= BITS (result));
 
   i0 = i / BITS (bitmap[0]);
   i1 = i % BITS (bitmap[0]);
@@ -229,7 +229,7 @@
 {
   uword i0, i1, l, t, m;
 
-  ASSERT (n_bits >= 0 && n_bits <= BITS (value));
+  ASSERT (n_bits <= BITS (value));
 
   i0 = i / BITS (bitmap[0]);
   i1 = i % BITS (bitmap[0]);
diff --git a/vppinfra/vppinfra/elf.c b/vppinfra/vppinfra/elf.c
index 7fe3048..71ae1d3 100644
--- a/vppinfra/vppinfra/elf.c
+++ b/vppinfra/vppinfra/elf.c
@@ -559,7 +559,8 @@
     s = format (s, "\nSections %d at file offset 0x%Lx-0x%Lx:\n",
 		fh->section_header_count,
 		fh->section_header_file_offset,
-		fh->section_header_file_offset + fh->section_header_count * fh->section_header_size);
+		fh->section_header_file_offset + 
+                (u64) fh->section_header_count * fh->section_header_size);
     s = format (s, "%U\n", format_elf_section, em, 0);
     vec_foreach (h, copy)
       s = format (s, "%U\n", format_elf_section, em, h);
@@ -1604,7 +1605,7 @@
 
       fh->section_header_file_offset = file_offset;
       fh->section_header_count = vec_len (em->sections) - n_deleted_sections;
-      file_offset += fh->section_header_count * fh->section_header_size;
+      file_offset += (u64) fh->section_header_count * fh->section_header_size;
     }
 
     {
@@ -1809,7 +1810,11 @@
 	  continue;
 
 	if (fseek (f, s->header.file_offset, SEEK_SET) < 0)
-	  return clib_error_return_unix (0, "fseek 0x%Lx", s->header.file_offset);
+          {
+            fclose(f);
+            return clib_error_return_unix (0, "fseek 0x%Lx", 
+                                           s->header.file_offset);
+          }
 
 	if (s->header.type == ELF_SECTION_NO_BITS)
 	  /* don't write for .bss sections */;
diff --git a/vppinfra/vppinfra/elf_clib.c b/vppinfra/vppinfra/elf_clib.c
index f3d3b32..8c70548 100644
--- a/vppinfra/vppinfra/elf_clib.c
+++ b/vppinfra/vppinfra/elf_clib.c
@@ -82,6 +82,9 @@
   if (file[0] == '.' || file[0] == '/')
     return file;
 
+  if (getenv("PATH") == 0)
+    return file;
+
   ps.path = split_string (getenv ("PATH"), ':');
 
   for (i = 0; i < vec_len (ps.path); i++)
@@ -231,7 +234,10 @@
 
       name = path_search (cem->exec_path);
       if (! name)
-	clib_error ("failed to find %s on PATH", cem->exec_path);
+        {
+          clib_error ("failed to find %s on PATH", cem->exec_path);
+          return 0;
+        }
       addr = 0;
     }
 
diff --git a/vppinfra/vppinfra/elog.c b/vppinfra/vppinfra/elog.c
index 06b97d8..7ae4ea1 100644
--- a/vppinfra/vppinfra/elog.c
+++ b/vppinfra/vppinfra/elog.c
@@ -582,6 +582,8 @@
   elog_track_t newt;
   int i;
 
+  memset(&newt, 0, sizeof (newt));
+
   elog_get_events (src);
   elog_get_events (dst);