VPP-1032: fix coverity warnings
Change-Id: Ic3a0c51e5408921051deaf2e50372d9654574b27
Signed-off-by: Dave Barach <dave@barachs.net>
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index e7382c2..24b6fb0 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -2137,6 +2137,7 @@
vam->client_index_invalid = 1;
+ /* Note: this closes memfd.fd */
retval = memfd_slave_init (&memfd);
if (retval)
clib_warning ("WARNING: segment map returned %d", retval);
@@ -2152,8 +2153,6 @@
vl_client_connect_to_vlib_no_map ("pvt",
"vpp_api_test(p)",
32 /* input_queue_length */ );
- if (close (my_fd) < 0)
- clib_unix_warning ("close memfd fd pivot");
vam->vl_input_queue = am->shmem_hdr->vl_input_queue;
vl_socket_client_enable_disable (&vam->socket_client_main,
@@ -20918,16 +20917,12 @@
static int
api_memfd_segment_create (vat_main_t * vam)
{
+#if VPP_API_TEST_BUILTIN == 0
unformat_input_t *i = vam->input;
vl_api_memfd_segment_create_t *mp;
u64 size = 64 << 20;
int ret;
-#if VPP_API_TEST_BUILTIN == 1
- errmsg ("memfd_segment_create (builtin) not supported");
- return -99;
-#endif
-
while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
{
if (unformat (i, "size %U", unformat_memory_size, &size))
@@ -20941,6 +20936,11 @@
S (mp);
W (ret);
return ret;
+
+#else
+ errmsg ("memfd_segment_create (builtin) not supported");
+ return -99;
+#endif
}
static int
diff --git a/src/vnet/dns/dns.c b/src/vnet/dns/dns.c
index 71ae7bb..9facb9b 100644
--- a/src/vnet/dns/dns.c
+++ b/src/vnet/dns/dns.c
@@ -690,6 +690,15 @@
if (dm->is_enabled == 0)
return VNET_API_ERROR_NAME_RESOLUTION_NOT_ENABLED;
+ /*
+ * Silence spurious coverity warning. We know pool_elts >> 0, or
+ * we wouldn't be here...
+ */
+#ifdef __COVERITY__
+ if (pool_elts (dm->entries) == 0)
+ return VNET_API_ERROR_UNSPECIFIED;
+#endif
+
dns_cache_lock (dm);
limit = pool_elts (dm->entries);
start_index = random_u32 (&dm->random_seed) % limit;
@@ -936,8 +945,7 @@
pos += len;
len = *pos++;
}
- qp = (dns_query_t *) pos;
- pos += sizeof (*qp);
+ pos += sizeof (dns_query_t);
}
pos2 = pos;
/* expect a pointer chase here for a CNAME record */
@@ -1122,7 +1130,7 @@
if ((pos[0] & 0xC0) == 0xC0)
{
curpos = pos + 2;
- break;
+ goto curpos_set;
}
pos += len;
len = *pos++;
@@ -1130,6 +1138,7 @@
curpos = pos;
}
+ curpos_set:
rr = (dns_rr_t *) curpos;
switch (clib_net_to_host_u16 (rr->type))
diff --git a/src/vppinfra/time.h b/src/vppinfra/time.h
index 3fdc7d4..288922d 100644
--- a/src/vppinfra/time.h
+++ b/src/vppinfra/time.h
@@ -263,10 +263,12 @@
always_inline void
unix_sleep (f64 dt)
{
- struct timespec t;
- t.tv_sec = dt;
- t.tv_nsec = 1e9 * dt;
- nanosleep (&t, 0);
+ struct timespec ts, tsrem;
+ ts.tv_sec = dt;
+ ts.tv_nsec = 1e9 * (dt - (f64) ts.tv_sec);
+
+ while (nanosleep (&ts, &tsrem) < 0)
+ ts = tsrem;
}
#else /* ! CLIB_UNIX */