stats: fix coverity issues 71/30271/2
authorAndrew Yourtchenko <ayourtch@gmail.com>
Fri, 4 Dec 2020 07:22:01 +0000 (07:22 +0000)
committerOle Tr�an <otroan@employees.org>
Fri, 4 Dec 2020 08:41:38 +0000 (08:41 +0000)
Usage of the possibly negative value with subsequent check on it
makes coverity very unhappy, so put the check before use.

Change-Id: I731fbe6246f9e4212d546fd9277bc1ddcd3c2ec1
Type: fix
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
src/vpp/stats/stat_segment.c

index 4244acb..0b5ea30 100644 (file)
@@ -330,13 +330,12 @@ vlib_map_stat_segment_init (void)
 
   mfd = clib_mem_vm_create_fd (sm->log2_page_sz, mem_name);
 
-  /* Set size */
-  if ((ftruncate (mfd, memory_size)) == -1)
-    return clib_error_return (0, "stat segment ftruncate failure");
-
   if (mfd == -1)
     return clib_error_return (0, "stat segment memory fd failure: %U",
                              format_clib_error, clib_mem_get_last_error ());
+  /* Set size */
+  if ((ftruncate (mfd, memory_size)) == -1)
+    return clib_error_return (0, "stat segment ftruncate failure");
 
   memaddr = clib_mem_vm_map_shared (0, memory_size, mfd, 0, mem_name);