Address some spurious Clang static analyzer warnings

Signed-off-by: Erik Boasson <eb@ilities.com>

Fix typo in dlopen_unknown test

Signed-off-by: Dennis Potman <dennis.potman@adlinktech.com>

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2020-01-19 17:00:18 +01:00 committed by eboasson
parent 97c3025e54
commit 68f789d77b
6 changed files with 20 additions and 10 deletions

View file

@ -403,6 +403,7 @@ void dds_qset_prop (dds_qos_t * __restrict qos, const char * name, const char *
dds_qprop_init (qos); dds_qprop_init (qos);
if (dds_qprop_get_index (qos, name, &i)) if (dds_qprop_get_index (qos, name, &i))
{ {
assert (&qos->property.value.props[i] != NULL); /* for Clang static analyzer */
dds_free (qos->property.value.props[i].value); dds_free (qos->property.value.props[i].value);
qos->property.value.props[i].value = dds_string_dup (value); qos->property.value.props[i].value = dds_string_dup (value);
} }
@ -426,6 +427,7 @@ void dds_qset_bprop (dds_qos_t * __restrict qos, const char * name, const void *
dds_qprop_init (qos); dds_qprop_init (qos);
if (dds_qbprop_get_index (qos, name, &i)) if (dds_qbprop_get_index (qos, name, &i))
{ {
assert (&qos->property.binary_value.props[i].value != NULL); /* for Clang static analyzer */
dds_qos_data_copy_in (&qos->property.binary_value.props[i].value, value, sz, true); dds_qos_data_copy_in (&qos->property.binary_value.props[i].value, value, sz, true);
} }
else else

View file

@ -11,6 +11,7 @@
*/ */
#include "CUnit/Test.h" #include "CUnit/Test.h"
#include "dds/dds.h" #include "dds/dds.h"
#include <assert.h>
/**************************************************************************** /****************************************************************************
* Convenience global policies * Convenience global policies
@ -746,6 +747,7 @@ CU_Test(ddsc_qos, bproperty, .init=qos_init, .fini=qos_fini)
CU_ASSERT_FATAL(dds_qget_bprop (g_qos, c_bproperty_names[0], &bvalue, &size)); CU_ASSERT_FATAL(dds_qget_bprop (g_qos, c_bproperty_names[0], &bvalue, &size));
CU_ASSERT_FATAL (bvalue != NULL); CU_ASSERT_FATAL (bvalue != NULL);
CU_ASSERT_EQUAL_FATAL (size, 3); CU_ASSERT_EQUAL_FATAL (size, 3);
assert (c_bproperty_values[0] != NULL); /* for Clang static analyzer */
CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[0], size), 0); CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[0], size), 0);
dds_free (bvalue); dds_free (bvalue);
@ -754,6 +756,7 @@ CU_Test(ddsc_qos, bproperty, .init=qos_init, .fini=qos_fini)
CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_bproperty_names[0], &bvalue, &size)); CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_bproperty_names[0], &bvalue, &size));
CU_ASSERT_FATAL (bvalue != NULL); CU_ASSERT_FATAL (bvalue != NULL);
CU_ASSERT_EQUAL_FATAL (size, 3); CU_ASSERT_EQUAL_FATAL (size, 3);
assert (c_bproperty_values[1] != NULL); /* for Clang static analyzer */
CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[1], size), 0); CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[1], size), 0);
dds_free (bvalue); dds_free (bvalue);
dds_qset_bprop (g_qos, c_bproperty_names[0], &c_bproperty_values[0], 3); dds_qset_bprop (g_qos, c_bproperty_names[0], &c_bproperty_values[0], 3);
@ -782,11 +785,13 @@ CU_Test(ddsc_qos, bproperty, .init=qos_init, .fini=qos_fini)
CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_bproperty_names[0], &bvalue, &size)); CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_bproperty_names[0], &bvalue, &size));
CU_ASSERT_FATAL (bvalue != NULL); CU_ASSERT_FATAL (bvalue != NULL);
CU_ASSERT_EQUAL_FATAL (size, 3); CU_ASSERT_EQUAL_FATAL (size, 3);
assert (c_bproperty_values[0] != NULL); /* for Clang static analyzer */
CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[0], size), 0); CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[0], size), 0);
dds_free (bvalue); dds_free (bvalue);
CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_bproperty_names[2], &bvalue, &size)); CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_bproperty_names[2], &bvalue, &size));
CU_ASSERT_FATAL (bvalue != NULL); CU_ASSERT_FATAL (bvalue != NULL);
CU_ASSERT_EQUAL_FATAL (size, 3); CU_ASSERT_EQUAL_FATAL (size, 3);
assert (c_bproperty_values[2] != NULL); /* for Clang static analyzer */
CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[2], size), 0); CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[2], size), 0);
dds_free (bvalue); dds_free (bvalue);
dds_qunset_bprop (g_qos, c_bproperty_names[0]); dds_qunset_bprop (g_qos, c_bproperty_names[0]);
@ -809,6 +814,7 @@ CU_Test(ddsc_qos, property_mixed, .init=qos_init, .fini=qos_fini)
CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_property_names[0], &bvalue, &size)); CU_ASSERT_FATAL (dds_qget_bprop (g_qos, c_property_names[0], &bvalue, &size));
CU_ASSERT_FATAL (bvalue != NULL); CU_ASSERT_FATAL (bvalue != NULL);
CU_ASSERT_EQUAL_FATAL (size, 3); CU_ASSERT_EQUAL_FATAL (size, 3);
assert (c_bproperty_values[0] != NULL); /* for Clang static analyzer */
CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[0], size), 0); CU_ASSERT_EQUAL_FATAL (memcmp (bvalue, c_bproperty_values[0], size), 0);
dds_free (bvalue); dds_free (bvalue);
CU_ASSERT_FATAL (dds_qget_prop (g_qos, c_property_names[0], &value)); CU_ASSERT_FATAL (dds_qget_prop (g_qos, c_property_names[0], &value));

View file

@ -584,7 +584,6 @@ static void send_heartbeat_to_all_readers(struct nn_xpack *xp, struct xevent *ev
{ {
struct whc_state whcst; struct whc_state whcst;
nn_mtime_t t_next; nn_mtime_t t_next;
int hbansreq = 0;
unsigned count = 0; unsigned count = 0;
ddsrt_mutex_lock (&wr->e.lock); ddsrt_mutex_lock (&wr->e.lock);
@ -592,21 +591,14 @@ static void send_heartbeat_to_all_readers(struct nn_xpack *xp, struct xevent *ev
whc_get_state(wr->whc, &whcst); whc_get_state(wr->whc, &whcst);
if (!writer_must_have_hb_scheduled (wr, &whcst)) if (!writer_must_have_hb_scheduled (wr, &whcst))
{
hbansreq = 1; /* just for trace */
t_next.v = T_NEVER; t_next.v = T_NEVER;
}
else if (!writer_hbcontrol_must_send (wr, &whcst, tnow)) else if (!writer_hbcontrol_must_send (wr, &whcst, tnow))
{
hbansreq = 1; /* just for trace */
t_next.v = tnow.v + writer_hbcontrol_intv (wr, &whcst, tnow); t_next.v = tnow.v + writer_hbcontrol_intv (wr, &whcst, tnow);
}
else else
{ {
struct wr_prd_match *m; struct wr_prd_match *m;
struct ddsi_guid last_guid = { .prefix = {.u = {0,0,0}}, .entityid = {0} }; struct ddsi_guid last_guid = { .prefix = {.u = {0,0,0}}, .entityid = {0} };
const int hbansreq = writer_hbcontrol_ack_required (wr, &whcst, tnow);
hbansreq = writer_hbcontrol_ack_required (wr, &whcst, tnow);
t_next.v = tnow.v + writer_hbcontrol_intv (wr, &whcst, tnow); t_next.v = tnow.v + writer_hbcontrol_intv (wr, &whcst, tnow);
while ((m = ddsrt_avl_lookup_succ (&wr_readers_treedef, &wr->readers, &last_guid)) != NULL) while ((m = ddsrt_avl_lookup_succ (&wr_readers_treedef, &wr->readers, &last_guid)) != NULL)

View file

@ -15,6 +15,7 @@
#include "dds/ddsrt/string.h" #include "dds/ddsrt/string.h"
#include "dds/ddsi/ddsi_security_msg.h" #include "dds/ddsi/ddsi_security_msg.h"
#include "mem_ser.h" #include "mem_ser.h"
#include <assert.h>
static nn_participant_generic_message_t test_msg_in = static nn_participant_generic_message_t test_msg_in =
{ {
@ -302,6 +303,7 @@ CU_Test (ddsi_security_msg, serializer)
/* Check serialization result. */ /* Check serialization result. */
size_t cmpsize = (len < sizeof(test_msg_ser)) ? len : sizeof(test_msg_ser); size_t cmpsize = (len < sizeof(test_msg_ser)) ? len : sizeof(test_msg_ser);
assert(data != NULL); /* for Clang static analyzer */
if (memcmp (data, test_msg_ser, cmpsize) != 0) if (memcmp (data, test_msg_ser, cmpsize) != 0)
{ {
printf ("memcmp(%d)\n", (int)cmpsize); printf ("memcmp(%d)\n", (int)cmpsize);

View file

@ -87,7 +87,7 @@ CU_Test(ddsrt_library, dlopen_unknown)
ddsrt_dynlib_t l; ddsrt_dynlib_t l;
r = ddsrt_dlopen("UnknownLib", false, &l); r = ddsrt_dlopen("UnknownLib", false, &l);
CU_ASSERT_NOT_EQUAL(r, DDS_RETCODE_OK);
CU_ASSERT_PTR_NULL_FATAL(l); CU_ASSERT_PTR_NULL_FATAL(l);
r = ddsrt_dlerror(buffer, sizeof(buffer)); r = ddsrt_dlerror(buffer, sizeof(buffer));
@ -123,6 +123,7 @@ CU_Test(ddsrt_library, dlsym_unknown)
void* f; void* f;
r = ddsrt_dlopen(TEST_LIB_NAME, true, &l); r = ddsrt_dlopen(TEST_LIB_NAME, true, &l);
CU_ASSERT_EQUAL(r, DDS_RETCODE_OK);
CU_ASSERT_PTR_NOT_NULL(l); CU_ASSERT_PTR_NOT_NULL(l);
TEST_ABORT_IF_NULL(l,"ddsrt_dlopen() failed. Is the proper library path set?"); TEST_ABORT_IF_NULL(l,"ddsrt_dlopen() failed. Is the proper library path set?");
@ -150,17 +151,21 @@ CU_Test(ddsrt_library, call)
ddsrt_dynlib_t l; ddsrt_dynlib_t l;
r = ddsrt_dlopen(TEST_LIB_NAME, true, &l); r = ddsrt_dlopen(TEST_LIB_NAME, true, &l);
CU_ASSERT_EQUAL(r, DDS_RETCODE_OK);
CU_ASSERT_PTR_NOT_NULL(l); CU_ASSERT_PTR_NOT_NULL(l);
TEST_ABORT_IF_NULL(l, "ddsrt_dlopen() failed. Is the proper library path set?"); TEST_ABORT_IF_NULL(l, "ddsrt_dlopen() failed. Is the proper library path set?");
r = ddsrt_dlsym(l, "get_int", (void **)&f_get); r = ddsrt_dlsym(l, "get_int", (void **)&f_get);
CU_ASSERT_EQUAL(r, DDS_RETCODE_OK);
CU_ASSERT_PTR_NOT_NULL(f_get); CU_ASSERT_PTR_NOT_NULL(f_get);
TEST_ABORT_IF_NULL(f_get, "ddsrt_dlsym(l, \"get_int\") failed."); TEST_ABORT_IF_NULL(f_get, "ddsrt_dlsym(l, \"get_int\") failed.");
r = ddsrt_dlsym(l, "set_int", (void **)&f_set); r = ddsrt_dlsym(l, "set_int", (void **)&f_set);
CU_ASSERT_EQUAL(r, DDS_RETCODE_OK);
CU_ASSERT_PTR_NOT_NULL(f_set); CU_ASSERT_PTR_NOT_NULL(f_set);
TEST_ABORT_IF_NULL(f_set, "ddsrt_dlsym(l, \"set_int\") failed."); TEST_ABORT_IF_NULL(f_set, "ddsrt_dlsym(l, \"set_int\") failed.");
assert(f_set != 0 && f_get != 0); /* for Clang static analyzer */
f_set(set_int); f_set(set_int);
get_int = f_get(); get_int = f_get();
CU_ASSERT_EQUAL(set_int, get_int); CU_ASSERT_EQUAL(set_int, get_int);
@ -175,6 +180,7 @@ CU_Test(ddsrt_library, dlclose_error)
ddsrt_dynlib_t l; ddsrt_dynlib_t l;
r = ddsrt_dlopen(TEST_LIB_NAME, true, &l); r = ddsrt_dlopen(TEST_LIB_NAME, true, &l);
CU_ASSERT_EQUAL(r, DDS_RETCODE_OK);
CU_ASSERT_PTR_NOT_NULL(l); CU_ASSERT_PTR_NOT_NULL(l);
TEST_ABORT_IF_NULL(l, "ddsrt_dlopen() failed. Is the proper library path set?"); TEST_ABORT_IF_NULL(l, "ddsrt_dlopen() failed. Is the proper library path set?");

View file

@ -10,6 +10,7 @@
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/ */
#include <string.h> #include <string.h>
#include <assert.h>
#include "CUnit/Theory.h" #include "CUnit/Theory.h"
#include "dds/ddsrt/heap.h" #include "dds/ddsrt/heap.h"
@ -82,6 +83,7 @@ CU_Theory((const char *str, const char *srch, const char *subst, size_t max, con
if (exp != NULL) if (exp != NULL)
{ {
CU_ASSERT_FATAL(r != NULL); CU_ASSERT_FATAL(r != NULL);
assert(r != NULL); /* for Clang static analyzer */
CU_ASSERT(strcmp(r, exp) == 0); CU_ASSERT(strcmp(r, exp) == 0);
ddsrt_free(r); ddsrt_free(r);
} }