diff --git a/src/core/ddsc/src/dds_domain.c b/src/core/ddsc/src/dds_domain.c index 9bfb67c..1300b75 100644 --- a/src/core/ddsc/src/dds_domain.c +++ b/src/core/ddsc/src/dds_domain.c @@ -169,7 +169,6 @@ static dds_return_t dds_domain_init (dds_domain *domain, dds_domainid_t domain_i dds_entity_init_complete (&domain->m_entity); return DDS_RETCODE_OK; - rtps_stop (&domain->gv); fail_rtps_start: if (domain->gv.config.liveliness_monitoring && dds_global.threadmon_count == 1) ddsi_threadmon_stop (dds_global.threadmon); diff --git a/src/core/ddsc/src/dds_entity.c b/src/core/ddsc/src/dds_entity.c index 3fcc523..56a5ce4 100644 --- a/src/core/ddsc/src/dds_entity.c +++ b/src/core/ddsc/src/dds_entity.c @@ -403,14 +403,17 @@ dds_return_t dds_delete_impl_pinned (dds_entity *e, enum delete_impl_state delst ddsrt_mutex_unlock (&p->m_mutex); } - /* Do some specific deletion when needed. Bootstrapping and its inverse are always a - tricky business, and here it is no different: deleting the pseudo-top-level object - tears down all kinds of stuff that is supposed to remain in existence (like the - entire platform abstraction) and so it must be the final call. Thus, we rely on it - to call "dds_entity_final_deinit_before_free" and return a special error code. */ + /* Do some specific deletion when needed */ ret = dds_entity_deriver_delete (e); if (ret == DDS_RETCODE_NO_DATA) + { + /* Bootstrapping and its inverse are always a tricky business, and here it is no different: + deleting the pseudo-top-level object tears down all kinds of stuff that is supposed to + remain in existence (like the entire platform abstraction) and so it must be the final + call. Thus, we rely on it to call "dds_entity_final_deinit_before_free" and return a + special error code that we don't pass on to the caller. */ ret = DDS_RETCODE_OK; + } else if (ret != DDS_RETCODE_OK) { if (parent_to_delete) @@ -423,6 +426,8 @@ dds_return_t dds_delete_impl_pinned (dds_entity *e, enum delete_impl_state delst dds_free (e); } + assert (ret == DDS_RETCODE_OK); + (void) ret; return (parent_to_delete != NULL) ? dds_delete_impl_pinned (parent_to_delete, DIS_IMPLICIT) : DDS_RETCODE_OK; } diff --git a/src/core/ddsc/src/dds_stream.c b/src/core/ddsc/src/dds_stream.c index 982a532..3f12777 100644 --- a/src/core/ddsc/src/dds_stream.c +++ b/src/core/ddsc/src/dds_stream.c @@ -1696,7 +1696,7 @@ static bool prtf_simple_array (char * __restrict *buf, size_t * __restrict bufsi else { if (i != 0) - cont = prtf (buf, bufsize, ","); + (void) prtf (buf, bufsize, ","); cont = prtf_simple (buf, bufsize, is, type); i++; } @@ -1708,7 +1708,7 @@ static bool prtf_simple_array (char * __restrict *buf, size_t * __restrict bufsi for (size_t i = 0; cont && i < num; i++) { if (i != 0) - cont = prtf (buf, bufsize, ","); + (void) prtf (buf, bufsize, ","); cont = prtf_simple (buf, bufsize, is, type); } break; diff --git a/src/core/ddsc/tests/entity_hierarchy.c b/src/core/ddsc/tests/entity_hierarchy.c index d52b34f..7983011 100644 --- a/src/core/ddsc/tests/entity_hierarchy.c +++ b/src/core/ddsc/tests/entity_hierarchy.c @@ -366,6 +366,7 @@ CU_Test(ddsc_entity_get_children, null, .init=hierarchy_init, .fini=hierarchy_fi /*************************************************************************************************/ /*************************************************************************************************/ +#if SIZE_MAX > INT32_MAX CU_Test(ddsc_entity_get_children, invalid_size, .init=hierarchy_init, .fini=hierarchy_fini) { dds_return_t ret; @@ -373,6 +374,7 @@ CU_Test(ddsc_entity_get_children, invalid_size, .init=hierarchy_init, .fini=hier ret = dds_get_children(g_participant, &child, SIZE_MAX); CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_BAD_PARAMETER); } +#endif /*************************************************************************************************/ /*************************************************************************************************/ diff --git a/src/core/ddsc/tests/instance_get_key.c b/src/core/ddsc/tests/instance_get_key.c index a0861b3..f8c4cf5 100644 --- a/src/core/ddsc/tests/instance_get_key.c +++ b/src/core/ddsc/tests/instance_get_key.c @@ -132,6 +132,7 @@ CU_Test(ddsc_instance_get_key, registered_instance, .init=setup, .fini=teardown) ret = dds_instance_get_key(writer, handle, &key_data); CU_ASSERT_PTR_NOT_NULL_FATAL(key_data.ip); + assert (key_data.ip != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_STRING_EQUAL_FATAL(key_data.ip, data.ip); CU_ASSERT_EQUAL_FATAL(key_data.port, data.port); CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); @@ -162,6 +163,7 @@ CU_Test(ddsc_instance_get_key, readcondition, .init=setup, .fini=teardown) ret = dds_instance_get_key(readcondition, handle, &key_data); CU_ASSERT_PTR_NOT_NULL_FATAL(key_data.ip); + assert (key_data.ip != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_STRING_EQUAL_FATAL(key_data.ip, data.ip); CU_ASSERT_EQUAL_FATAL(key_data.port, data.port); CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); @@ -192,6 +194,7 @@ CU_Test(ddsc_instance_get_key, querycondition, .init=setup, .fini=teardown) ret = dds_instance_get_key(querycondition, handle, &key_data); CU_ASSERT_PTR_NOT_NULL_FATAL(key_data.ip); + assert (key_data.ip != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_STRING_EQUAL_FATAL(key_data.ip, data.ip); CU_ASSERT_EQUAL_FATAL(key_data.port, data.port); CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); diff --git a/src/core/ddsc/tests/listener.c b/src/core/ddsc/tests/listener.c index b0b42a7..2b5aa00 100644 --- a/src/core/ddsc/tests/listener.c +++ b/src/core/ddsc/tests/listener.c @@ -727,7 +727,9 @@ CU_Test(ddsc_listener, publication_matched, .init=init_triggering_test, .fini=fi CU_ASSERT_EQUAL_FATAL(publication_matched.last_subscription_handle, reader_hdl); /* Reset the trigger flags. */ + ddsrt_mutex_lock(&g_mutex); cb_called = 0; + ddsrt_mutex_unlock(&g_mutex); /* Un-match the publication by deleting the reader. */ dds_delete(g_reader); @@ -789,7 +791,9 @@ CU_Test(ddsc_listener, subscription_matched, .init=init_triggering_test, .fini=f CU_ASSERT_EQUAL_FATAL(subscription_matched.last_publication_handle, writer_hdl); /* Reset the trigger flags. */ + ddsrt_mutex_lock(&g_mutex); cb_called = 0; + ddsrt_mutex_unlock(&g_mutex); /* Un-match the subscription by deleting the writer. */ dds_delete(g_writer); @@ -903,8 +907,10 @@ CU_Test(ddsc_listener, data_available, .init=init_triggering_test, .fini=fini_tr /* Deleting the writer causes unregisters (or dispose+unregister), and those should trigger DATA_AVAILABLE as well */ + ddsrt_mutex_lock(&g_mutex); cb_called = 0; cb_reader = 0; + ddsrt_mutex_unlock(&g_mutex); ret = dds_delete (g_writer); CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); g_writer = 0; @@ -942,8 +948,10 @@ CU_Test(ddsc_listener, data_available_delete_writer, .init=init_triggering_test, CU_ASSERT_EQUAL_FATAL(cb_reader, g_reader); /* Deleting the writer must trigger DATA_AVAILABLE as well */ + ddsrt_mutex_lock(&g_mutex); cb_called = 0; cb_reader = 0; + ddsrt_mutex_unlock(&g_mutex); ret = dds_delete (g_writer); CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); g_writer = 0; @@ -991,8 +999,10 @@ CU_Test(ddsc_listener, data_available_delete_writer_disposed, .init=init_trigger } while (ret > 0); /* Deleting the writer should not trigger DATA_AVAILABLE with all instances empty & disposed */ + ddsrt_mutex_lock(&g_mutex); cb_called = 0; cb_reader = 0; + ddsrt_mutex_unlock(&g_mutex); ret = dds_delete (g_writer); CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); g_writer = 0; @@ -1174,7 +1184,9 @@ CU_Test(ddsc_listener, liveliness_changed, .init=init_triggering_test, .fini=fin CU_ASSERT_EQUAL_FATAL(liveliness_changed.last_publication_handle, writer_hdl); /* Reset the trigger flags. */ + ddsrt_mutex_lock(&g_mutex); cb_called = 0; + ddsrt_mutex_unlock(&g_mutex); /* Change liveliness again by deleting the writer. */ dds_delete(g_writer); diff --git a/src/core/ddsc/tests/participant.c b/src/core/ddsc/tests/participant.c index 23d5d42..6100f5d 100644 --- a/src/core/ddsc/tests/participant.c +++ b/src/core/ddsc/tests/participant.c @@ -47,7 +47,8 @@ CU_Test(ddsc_participant, create_with_no_conf_no_env) dds_domainid_t domain_id; dds_domainid_t valid_domain=3; - ddsrt_unsetenv(DDS_PROJECT_NAME_NOSPACE_CAPS"_URI"); + status = ddsrt_unsetenv(DDS_PROJECT_NAME_NOSPACE_CAPS"_URI"); + CU_ASSERT_EQUAL_FATAL(status, DDS_RETCODE_OK); //valid specific domain value participant2 = dds_create_participant (valid_domain, NULL, NULL); diff --git a/src/core/ddsi/include/dds/ddsi/q_entity.h b/src/core/ddsi/include/dds/ddsi/q_entity.h index c73876b..09069c9 100644 --- a/src/core/ddsi/include/dds/ddsi/q_entity.h +++ b/src/core/ddsi/include/dds/ddsi/q_entity.h @@ -91,7 +91,7 @@ struct wr_prd_match { seqno_t min_seq; /* smallest ack'd seq nr in subtree */ seqno_t max_seq; /* sort-of highest ack'd seq nr in subtree (see augment function) */ seqno_t seq; /* highest acknowledged seq nr */ - int num_reliable_readers_where_seq_equals_max; + int32_t num_reliable_readers_where_seq_equals_max; ddsi_guid_t arbitrary_unacked_reader; nn_count_t next_acknack; /* next acceptable acknack sequence number */ nn_count_t next_nackfrag; /* next acceptable nackfrag sequence number */ @@ -260,7 +260,7 @@ struct writer uint32_t whc_low, whc_high; /* watermarks for WHC in bytes (counting only unack'd data) */ nn_etime_t t_rexmit_end; /* time of last 1->0 transition of "retransmitting" */ nn_etime_t t_whc_high_upd; /* time "whc_high" was last updated for controlled ramp-up of throughput */ - int num_reliable_readers; /* number of matching reliable PROXY readers */ + int32_t num_reliable_readers; /* number of matching reliable PROXY readers */ ddsrt_avl_tree_t readers; /* all matching PROXY readers, see struct wr_prd_match */ ddsrt_avl_tree_t local_readers; /* all matching LOCAL readers, see struct wr_rd_match */ #ifdef DDSI_INCLUDE_NETWORK_PARTITIONS @@ -356,8 +356,8 @@ struct proxy_writer { struct entity_common e; struct proxy_endpoint_common c; ddsrt_avl_tree_t readers; /* matching LOCAL readers, see pwr_rd_match */ - int n_reliable_readers; /* number of those that are reliable */ - int n_readers_out_of_sync; /* number of those that require special handling (accepting historical data, waiting for historical data set to become complete) */ + int32_t n_reliable_readers; /* number of those that are reliable */ + int32_t n_readers_out_of_sync; /* number of those that require special handling (accepting historical data, waiting for historical data set to become complete) */ seqno_t last_seq; /* highest known seq published by the writer, not last delivered */ uint32_t last_fragnum; /* last known frag for last_seq, or ~0u if last_seq not partial */ nn_count_t nackfragcount; /* last nackfrag seq number */ diff --git a/src/core/ddsi/src/ddsi_raweth.c b/src/core/ddsi/src/ddsi_raweth.c index cc09ad1..bdb9e27 100644 --- a/src/core/ddsi/src/ddsi_raweth.c +++ b/src/core/ddsi/src/ddsi_raweth.c @@ -211,7 +211,12 @@ static ddsi_tran_conn_t ddsi_raweth_create_conn (ddsi_tran_factory_t fact, uint3 return NULL; } - uc = (ddsi_raweth_conn_t) ddsrt_malloc (sizeof (*uc)); + if ((uc = (ddsi_raweth_conn_t) ddsrt_malloc (sizeof (*uc))) == NULL) + { + ddsrt_close(sock); + return NULL; + } + memset (uc, 0, sizeof (*uc)); uc->m_sock = sock; uc->m_ifindex = addr.sll_ifindex; @@ -226,7 +231,7 @@ static ddsi_tran_conn_t ddsi_raweth_create_conn (ddsi_tran_factory_t fact, uint3 uc->m_base.m_disable_multiplexing_fn = 0; DDS_CTRACE (&fact->gv->logconfig, "ddsi_raweth_create_conn %s socket %d port %u\n", mcast ? "multicast" : "unicast", uc->m_sock, uc->m_base.m_base.m_port); - return uc ? &uc->m_base : NULL; + return &uc->m_base; } static int isbroadcast(const nn_locator_t *loc) diff --git a/src/core/ddsi/src/ddsi_tcp.c b/src/core/ddsi/src/ddsi_tcp.c index 9c7fb41..778d733 100644 --- a/src/core/ddsi/src/ddsi_tcp.c +++ b/src/core/ddsi/src/ddsi_tcp.c @@ -554,8 +554,9 @@ static ssize_t ddsi_tcp_conn_write (ddsi_tran_conn_t base, const nn_locator_t *d /* If not connected attempt to conect */ - if ((conn->m_sock == DDSRT_INVALID_SOCKET) && ! conn->m_base.m_server) + if (conn->m_sock == DDSRT_INVALID_SOCKET) { + assert (!conn->m_base.m_server); ddsi_tcp_conn_connect (conn, &msg); if (conn->m_sock == DDSRT_INVALID_SOCKET) { diff --git a/src/core/ddsi/src/ddsi_threadmon.c b/src/core/ddsi/src/ddsi_threadmon.c index 346b0b9..53139e9 100644 --- a/src/core/ddsi/src/ddsi_threadmon.c +++ b/src/core/ddsi/src/ddsi_threadmon.c @@ -265,7 +265,7 @@ void ddsi_threadmon_unregister_domain (struct ddsi_threadmon *sl, const struct q dummy.gv = gv; struct threadmon_domain *tmdom = ddsrt_hh_lookup (sl->domains, &dummy); assert (tmdom); - ddsrt_hh_remove (sl->domains, tmdom); + (void) ddsrt_hh_remove (sl->domains, tmdom); ddsrt_mutex_unlock (&sl->lock); ddsrt_free (tmdom); } diff --git a/src/core/ddsi/src/q_config.c b/src/core/ddsi/src/q_config.c index 9ea3ef0..8a0982b 100644 --- a/src/core/ddsi/src/q_config.c +++ b/src/core/ddsi/src/q_config.c @@ -1012,6 +1012,8 @@ static size_t cfg_note_vsnprintf (struct cfg_note_buf *bb, const char *fmt, va_l return 0; } +static void cfg_note_snprintf (struct cfg_note_buf *bb, const char *fmt, ...) ddsrt_attribute_format ((printf, 2, 3)); + static void cfg_note_snprintf (struct cfg_note_buf *bb, const char *fmt, ...) { /* The reason the 2nd call to os_vsnprintf is here and not inside @@ -1123,6 +1125,8 @@ static size_t cfg_note (struct cfgst *cfgst, uint32_t cat, size_t bsz, const cha return 0; } +static void cfg_warning (struct cfgst *cfgst, const char *fmt, ...) ddsrt_attribute_format ((printf, 2, 3)); + static void cfg_warning (struct cfgst *cfgst, const char *fmt, ...) { va_list ap; @@ -1134,6 +1138,8 @@ static void cfg_warning (struct cfgst *cfgst, const char *fmt, ...) } while (bsz > 0); } +static enum update_result cfg_error (struct cfgst *cfgst, const char *fmt, ...) ddsrt_attribute_format ((printf, 2, 3)); + static enum update_result cfg_error (struct cfgst *cfgst, const char *fmt, ...) { va_list ap; @@ -1146,6 +1152,8 @@ static enum update_result cfg_error (struct cfgst *cfgst, const char *fmt, ...) return URES_ERROR; } +static void cfg_logelem (struct cfgst *cfgst, uint32_t sources, const char *fmt, ...) ddsrt_attribute_format ((printf, 3, 4)); + static void cfg_logelem (struct cfgst *cfgst, uint32_t sources, const char *fmt, ...) { /* 89 = 1 + 2 + 31 + 1 + 10 + 2*22: the number of characters in @@ -1444,7 +1452,7 @@ static void pf_int64_unit (struct cfgst *cfgst, int64_t value, uint32_t sources, } assert (m > 0); assert (unit != NULL); - cfg_logelem (cfgst, sources, "%lld %s", value / m, unit); + cfg_logelem (cfgst, sources, "%"PRId64" %s", value / m, unit); } } diff --git a/src/core/ddsi/src/q_ddsi_discovery.c b/src/core/ddsi/src/q_ddsi_discovery.c index 410c4b0..74d025a 100644 --- a/src/core/ddsi/src/q_ddsi_discovery.c +++ b/src/core/ddsi/src/q_ddsi_discovery.c @@ -21,6 +21,7 @@ #include "dds/ddsrt/md5.h" #include "dds/ddsrt/sync.h" #include "dds/ddsrt/avl.h" +#include "dds/ddsrt/string.h" #include "dds/ddsi/q_protocol.h" #include "dds/ddsi/q_rtps.h" #include "dds/ddsi/q_misc.h" @@ -302,8 +303,8 @@ int spdp_write (struct participant *pp) ps.prismtech_participant_version_info.flags |= NN_PRISMTECH_FL_PARTICIPANT_IS_DDSI2; ddsrt_mutex_unlock (&pp->e.gv->privileged_pp_lock); - ddsrt_gethostname(node, sizeof(node)-1); - node[sizeof(node)-1] = '\0'; + if (ddsrt_gethostname(node, sizeof(node)-1) < 0) + ddsrt_strlcpy (node, "unknown", sizeof (node)); size = strlen(node) + strlen(DDS_VERSION) + strlen(DDS_HOST_NAME) + strlen(DDS_TARGET_NAME) + 4; /* + ///'\0' */ ps.prismtech_participant_version_info.internals = ddsrt_malloc(size); (void) snprintf(ps.prismtech_participant_version_info.internals, size, "%s/%s/%s/%s", node, DDS_VERSION, DDS_HOST_NAME, DDS_TARGET_NAME); diff --git a/src/core/ddsi/src/q_debmon.c b/src/core/ddsi/src/q_debmon.c index c11b78c..8e629b6 100644 --- a/src/core/ddsi/src/q_debmon.c +++ b/src/core/ddsi/src/q_debmon.c @@ -57,6 +57,8 @@ struct debug_monitor { int stop; }; +static int cpf (ddsi_tran_conn_t conn, const char *fmt, ...) ddsrt_attribute_format ((printf, 2, 3)); + static int cpf (ddsi_tran_conn_t conn, const char *fmt, ...) { nn_locator_t loc; @@ -110,7 +112,7 @@ static int print_addrset_if_notempty (ddsi_tran_conn_t conn, const char *prefix, static int print_any_endpoint_common (ddsi_tran_conn_t conn, const char *label, const struct entity_common *e, const struct dds_qos *xqos) { int x = 0; - x += cpf (conn, " %s %x:%x:%x:%x ", label, PGUID (e->guid)); + x += cpf (conn, " %s "PGUIDFMT" ", label, PGUID (e->guid)); if (xqos->present & QP_PARTITION) { if (xqos->partition.n > 1) cpf (conn, "{"); @@ -150,7 +152,7 @@ static int print_participants (struct thread_state1 * const ts1, struct q_global while ((p = ephash_enum_participant_next (&e)) != NULL) { ddsrt_mutex_lock (&p->e.lock); - x += cpf (conn, "pp %x:%x:%x:%x %s%s\n", PGUID (p->e.guid), p->e.name, p->is_ddsi2_pp ? " [ddsi2]" : ""); + x += cpf (conn, "pp "PGUIDFMT" %s%s\n", PGUID (p->e.guid), p->e.name, p->is_ddsi2_pp ? " [ddsi2]" : ""); ddsrt_mutex_unlock (&p->e.lock); { @@ -169,7 +171,7 @@ static int print_participants (struct thread_state1 * const ts1, struct q_global x += print_addrset_if_notempty (conn, " as", r->as, "\n"); #endif for (m = ddsrt_avl_iter_first (&rd_writers_treedef, &r->writers, &writ); m; m = ddsrt_avl_iter_next (&writ)) - x += cpf (conn, " pwr %x:%x:%x:%x\n", PGUID (m->pwr_guid)); + x += cpf (conn, " pwr "PGUIDFMT"\n", PGUID (m->pwr_guid)); ddsrt_mutex_unlock (&r->e.lock); } ephash_enum_reader_fini (&er); @@ -189,20 +191,20 @@ static int print_participants (struct thread_state1 * const ts1, struct q_global ddsrt_mutex_lock (&w->e.lock); print_endpoint_common (conn, "wr", &w->e, &w->c, w->xqos); whc_get_state(w->whc, &whcst); - x += cpf (conn, " whc [%lld,%lld] unacked %"PRIuSIZE"%s [%u,%u] seq %lld seq_xmit %lld cs_seq %lld\n", + x += cpf (conn, " whc [%"PRId64",%"PRId64"] unacked %"PRIuSIZE"%s [%"PRIu32",%"PRIu32"] seq %"PRId64" seq_xmit %"PRId64" cs_seq %"PRId64"\n", whcst.min_seq, whcst.max_seq, whcst.unacked_bytes, w->throttling ? " THROTTLING" : "", w->whc_low, w->whc_high, w->seq, READ_SEQ_XMIT(w), w->cs_seq); if (w->reliable) { - x += cpf (conn, " hb %u ackhb %lld hb %lld wr %lld sched %lld #rel %d\n", - w->hbcontrol.hbs_since_last_write, w->hbcontrol.t_of_last_ackhb, - w->hbcontrol.t_of_last_hb, w->hbcontrol.t_of_last_write, - w->hbcontrol.tsched, w->num_reliable_readers); - x += cpf (conn, " #acks %u #nacks %u #rexmit %u #lost %u #throttle %u\n", + x += cpf (conn, " hb %"PRIu32" ackhb %"PRId64" hb %"PRId64" wr %"PRId64" sched %"PRId64" #rel %"PRId32"\n", + w->hbcontrol.hbs_since_last_write, w->hbcontrol.t_of_last_ackhb.v, + w->hbcontrol.t_of_last_hb.v, w->hbcontrol.t_of_last_write.v, + w->hbcontrol.tsched.v, w->num_reliable_readers); + x += cpf (conn, " #acks %"PRIu32" #nacks %"PRIu32" #rexmit %"PRIu32" #lost %"PRIu32" #throttle %"PRIu32"\n", w->num_acks_received, w->num_nacks_received, w->rexmit_count, w->rexmit_lost_count, w->throttle_count); - x += cpf (conn, " max-drop-seq %lld\n", writer_max_drop_seq (w)); + x += cpf (conn, " max-drop-seq %"PRId64"\n", writer_max_drop_seq (w)); } x += print_addrset_if_notempty (conn, " as", w->as, "\n"); for (m = ddsrt_avl_iter_first (&wr_readers_treedef, &w->readers, &rdit); m; m = ddsrt_avl_iter_next (&rdit)) @@ -212,7 +214,7 @@ static int print_participants (struct thread_state1 * const ts1, struct q_global wr_prd_flags[1] = m->assumed_in_sync ? 's' : '.'; wr_prd_flags[2] = m->has_replied_to_hb ? 'a' : '.'; /* a = ack seen */ wr_prd_flags[3] = 0; - x += cpf (conn, " prd %x:%x:%x:%x %s @ %lld [%lld,%lld] #nacks %u\n", + x += cpf (conn, " prd "PGUIDFMT" %s @ %"PRId64" [%"PRId64",%"PRId64"] #nacks %"PRIu32"\n", PGUID (m->prd_guid), wr_prd_flags, m->seq, m->min_seq, m->max_seq, m->rexmit_requests); } ddsrt_mutex_unlock (&w->e.lock); @@ -235,7 +237,7 @@ static int print_proxy_participants (struct thread_state1 * const ts1, struct q_ while ((p = ephash_enum_proxy_participant_next (&e)) != NULL) { ddsrt_mutex_lock (&p->e.lock); - x += cpf (conn, "proxypp %x:%x:%x:%x%s\n", PGUID (p->e.guid), p->is_ddsi2_pp ? " [ddsi2]" : ""); + x += cpf (conn, "proxypp "PGUIDFMT"%s\n", PGUID (p->e.guid), p->is_ddsi2_pp ? " [ddsi2]" : ""); ddsrt_mutex_unlock (&p->e.lock); x += print_addrset (conn, " as data", p->as_default, ""); x += print_addrset (conn, " meta", p->as_default, "\n"); @@ -253,7 +255,7 @@ static int print_proxy_participants (struct thread_state1 * const ts1, struct q_ ddsrt_mutex_lock (&r->e.lock); print_proxy_endpoint_common (conn, "prd", &r->e, &r->c); for (m = ddsrt_avl_iter_first (&rd_writers_treedef, &r->writers, &writ); m; m = ddsrt_avl_iter_next (&writ)) - x += cpf (conn, " wr %x:%x:%x:%x\n", PGUID (m->wr_guid)); + x += cpf (conn, " wr "PGUIDFMT"\n", PGUID (m->wr_guid)); ddsrt_mutex_unlock (&r->e.lock); } ephash_enum_proxy_reader_fini (&er); @@ -271,20 +273,20 @@ static int print_proxy_participants (struct thread_state1 * const ts1, struct q_ continue; ddsrt_mutex_lock (&w->e.lock); print_proxy_endpoint_common (conn, "pwr", &w->e, &w->c); - x += cpf (conn, " last_seq %lld last_fragnum %u\n", w->last_seq, w->last_fragnum); + x += cpf (conn, " last_seq %"PRId64" last_fragnum %"PRIu32"\n", w->last_seq, w->last_fragnum); for (m = ddsrt_avl_iter_first (&wr_readers_treedef, &w->readers, &rdit); m; m = ddsrt_avl_iter_next (&rdit)) { - x += cpf (conn, " rd %x:%x:%x:%x (nack %lld %lld)\n", - PGUID (m->rd_guid), m->seq_last_nack, m->t_last_nack); + x += cpf (conn, " rd "PGUIDFMT" (nack %"PRId64" %"PRId64")\n", + PGUID (m->rd_guid), m->seq_last_nack, m->t_last_nack.v); switch (m->in_sync) { case PRMSS_SYNC: break; case PRMSS_TLCATCHUP: - x += cpf (conn, " tl-catchup end_of_tl_seq %lld\n", m->u.not_in_sync.end_of_tl_seq); + x += cpf (conn, " tl-catchup end_of_tl_seq %"PRId64"\n", m->u.not_in_sync.end_of_tl_seq); break; case PRMSS_OUT_OF_SYNC: - x += cpf (conn, " out-of-sync end_of_tl_seq %lld\n", m->u.not_in_sync.end_of_tl_seq); + x += cpf (conn, " out-of-sync end_of_tl_seq %"PRId64"\n", m->u.not_in_sync.end_of_tl_seq); break; } } diff --git a/src/core/ddsi/src/q_receive.c b/src/core/ddsi/src/q_receive.c index f877606..f08d9bb 100644 --- a/src/core/ddsi/src/q_receive.c +++ b/src/core/ddsi/src/q_receive.c @@ -1071,7 +1071,7 @@ static void handle_Heartbeat_helper (struct pwr_rd_match * const wn, struct hand refseq = nn_reorder_next_seq (pwr->reorder) - 1; else refseq = nn_reorder_next_seq (wn->u.not_in_sync.reorder) - 1; - RSTTRACE (" "PGUIDFMT"@%"PRId64"%s", PGUID (wn->rd_guid), refseq, (wn->in_sync == PRMSS_SYNC) ? "(sync)" : (wn->in_sync == PRMSS_TLCATCHUP) ? "(tlcatchup)" : ""); + RSTTRACE (" "PGUIDFMT"@%"PRId64"%s", PGUID (wn->rd_guid), refseq, (wn->in_sync == PRMSS_SYNC) ? "(sync)" : (wn->in_sync == PRMSS_TLCATCHUP) ? "(tlcatchup)" : ""); /* Reschedule AckNack transmit if deemed appropriate; unreliable readers have acknack_xevent == NULL and can't do this. @@ -2437,7 +2437,7 @@ static int handle_DataFrag (struct receiver_state *rst, nn_etime_t tnow, struct payload_offset = submsg_offset + (unsigned) size; begin = (msg->fragmentStartingNum - 1) * msg->fragmentSize; - if (msg->fragmentSize * msg->fragmentsInSubmessage > ((unsigned char *) msg + size - datap)) { + if ((uint32_t) msg->fragmentSize * msg->fragmentsInSubmessage > (uint32_t) ((unsigned char *) msg + size - datap)) { /* this happens for the last fragment (which usually is short) -- and is included here merely as a sanity check, because that would mean the computed endp1'd be larger than the sample diff --git a/src/core/ddsi/src/q_sockwaitset.c b/src/core/ddsi/src/q_sockwaitset.c index e0cecef..dabff22 100644 --- a/src/core/ddsi/src/q_sockwaitset.c +++ b/src/core/ddsi/src/q_sockwaitset.c @@ -618,12 +618,23 @@ static void os_sockWaitsetNewSet (os_sockWaitsetSet * set) set->n = 1; } +static void os_sockWaitsetFreeSet (os_sockWaitsetSet * set) +{ + ddsrt_free (set->fds); + ddsrt_free (set->conns); +} + static void os_sockWaitsetNewCtx (os_sockWaitsetCtx ctx) { os_sockWaitsetNewSet (&ctx->set); FD_ZERO (&ctx->rdset); } +static void os_sockWaitsetFreeCtx (os_sockWaitsetCtx ctx) +{ + os_sockWaitsetFreeSet (&ctx->set); +} + os_sockWaitset os_sockWaitsetNew (void) { int result; @@ -642,40 +653,16 @@ os_sockWaitset os_sockWaitsetNew (void) ws->pipe[0] = -1; ws->pipe[1] = -1; result = 0; -#elif defined(__VXWORKS__) - int make_pipe (int pfd[2]) - { - char pipename[OSPL_PIPENAMESIZE]; - int pipecount=0; - do - { - snprintf ((char*)&pipename, sizeof(pipename), "/pipe/ospl%d", pipecount++ ); - } - while ((result = pipeDevCreate ((char*) &pipename, 1, 1)) == -1 && os_getErrno() == EINVAL); - if (result != -1) - { - result = open ((char*) &pipename, O_RDWR, 0644); - if (result != -1) - { - ws->pipe[0] = result; - result = open ((char*) &pipename, O_RDWR, 0644); - if (result != -1) - { - ws->pipe[1] = result; - } - else - { - close (ws->pipe[0]); - pipeDevDelete (pipename, 0); - } - } - } - } #else result = make_pipe (ws->pipe); #endif - assert (result != -1); - (void) result; + if (result == -1) + { + os_sockWaitsetFreeCtx (&ws->ctx); + os_sockWaitsetFreeSet (&ws->set); + ddsrt_free (ws); + return NULL; + } #if !defined(LWIP_SOCKET) ws->set.fds[0] = ws->pipe[0]; @@ -685,8 +672,8 @@ os_sockWaitset os_sockWaitsetNew (void) ws->set.conns[0] = NULL; #if !defined(__VXWORKS__) && !defined(_WIN32) && !defined(LWIP_SOCKET) - fcntl (ws->pipe[0], F_SETFD, fcntl (ws->pipe[0], F_GETFD) | FD_CLOEXEC); - fcntl (ws->pipe[1], F_SETFD, fcntl (ws->pipe[1], F_GETFD) | FD_CLOEXEC); + (void) fcntl (ws->pipe[0], F_SETFD, fcntl (ws->pipe[0], F_GETFD) | FD_CLOEXEC); + (void) fcntl (ws->pipe[1], F_SETFD, fcntl (ws->pipe[1], F_GETFD) | FD_CLOEXEC); #endif #if !defined(LWIP_SOCKET) FD_SET (ws->set.fds[0], &ws->ctx.rdset); @@ -707,17 +694,6 @@ static void os_sockWaitsetGrow (os_sockWaitsetSet * set) set->fds = ddsrt_realloc (set->fds, set->sz * sizeof (*set->fds)); } -static void os_sockWaitsetFreeSet (os_sockWaitsetSet * set) -{ - ddsrt_free (set->fds); - ddsrt_free (set->conns); -} - -static void os_sockWaitsetFreeCtx (os_sockWaitsetCtx ctx) -{ - os_sockWaitsetFreeSet (&ctx->set); -} - void os_sockWaitsetFree (os_sockWaitset ws) { #if defined(__VXWORKS__) && defined(__RTP__) diff --git a/src/core/ddsi/src/q_transmit.c b/src/core/ddsi/src/q_transmit.c index 94799ea..1f2a150 100644 --- a/src/core/ddsi/src/q_transmit.c +++ b/src/core/ddsi/src/q_transmit.c @@ -163,7 +163,7 @@ struct nn_xmsg *writer_hbcontrol_create_heartbeat (struct writer *wr, const stru } else { - const int n_unacked = wr->num_reliable_readers - root_rdmatch (wr)->num_reliable_readers_where_seq_equals_max; + const int32_t n_unacked = wr->num_reliable_readers - root_rdmatch (wr)->num_reliable_readers_where_seq_equals_max; assert (n_unacked >= 0); if (n_unacked == 0) prd_guid = NULL; @@ -182,7 +182,7 @@ struct nn_xmsg *writer_hbcontrol_create_heartbeat (struct writer *wr, const stru ETRACE (wr, "multicasting "); else ETRACE (wr, "unicasting to prd "PGUIDFMT" ", PGUID (*prd_guid)); - ETRACE (wr, "(rel-prd %d seq-eq-max %d seq %"PRId64" maxseq %"PRId64")\n", + ETRACE (wr, "(rel-prd %"PRId32" seq-eq-max %"PRId32" seq %"PRId64" maxseq %"PRId64")\n", wr->num_reliable_readers, ddsrt_avl_is_empty (&wr->readers) ? -1 : root_rdmatch (wr)->num_reliable_readers_where_seq_equals_max, wr->seq, diff --git a/src/ddsrt/src/retcode.c b/src/ddsrt/src/retcode.c index 930a327..5cd0590 100644 --- a/src/ddsrt/src/retcode.c +++ b/src/ddsrt/src/retcode.c @@ -10,6 +10,7 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include "dds/ddsrt/retcode.h" +#include "dds/ddsrt/static_assert.h" static const char *retcodes[] = { "Success", @@ -45,6 +46,7 @@ const char *dds_strretcode (dds_return_t rc) { const dds_return_t nretcodes = (dds_return_t) (sizeof (retcodes) / sizeof (retcodes[0])); const dds_return_t nxretcodes = (dds_return_t) (sizeof (xretcodes) / sizeof (xretcodes[0])); + DDSRT_STATIC_ASSERT (DDS_XRETCODE_BASE < 0); /* Retcodes used to be positive, but return values from the API would be a negative and so there are/were/may be places outside the core library where dds_strretcode is called with a -N for N a API return value, so ... play it safe and use the @@ -53,8 +55,8 @@ const char *dds_strretcode (dds_return_t rc) rc = -rc; if (rc >= 0 && rc < nretcodes) return retcodes[rc]; - else if (rc >= DDS_XRETCODE_BASE && rc < DDS_XRETCODE_BASE + nxretcodes) - return xretcodes[rc - DDS_XRETCODE_BASE]; + else if (rc >= (-DDS_XRETCODE_BASE) && rc < (-DDS_XRETCODE_BASE) + nxretcodes) + return xretcodes[rc - (-DDS_XRETCODE_BASE)]; else return "Unknown return code"; } diff --git a/src/ddsrt/tests/environ.c b/src/ddsrt/tests/environ.c index 6e22876..0a11334 100644 --- a/src/ddsrt/tests/environ.c +++ b/src/ddsrt/tests/environ.c @@ -10,6 +10,7 @@ * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ #include +#include #include "CUnit/Theory.h" #include "dds/ddsrt/environ.h" @@ -49,11 +50,13 @@ CU_Test(ddsrt_environ, setenv) CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); ptr = getenv(name); CU_ASSERT_PTR_NOT_NULL(ptr); + assert (ptr != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_STRING_EQUAL(ptr, "bar"); /* Ensure value is copied into the environment. */ value[2] = 'z'; ptr = getenv(name); CU_ASSERT_PTR_NOT_NULL(ptr); + assert (ptr != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_STRING_EQUAL(ptr, "bar"); rc = ddsrt_setenv(name, ""); CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK); diff --git a/src/ddsrt/tests/ifaddrs.c b/src/ddsrt/tests/ifaddrs.c index 6035724..13dda43 100644 --- a/src/ddsrt/tests/ifaddrs.c +++ b/src/ddsrt/tests/ifaddrs.c @@ -9,6 +9,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause */ +#include #include "dds/ddsrt/cdtors.h" #include "dds/ddsrt/ifaddrs.h" #include "dds/ddsrt/retcode.h" @@ -73,6 +74,7 @@ CU_Test(ddsrt_getifaddrs, ipv4) CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); for (ifa = ifa_root; ifa; ifa = ifa->next) { CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); + assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET); if (ifa->addr->sa_family == AF_INET) { if (ifa->flags & IFF_LOOPBACK) { @@ -130,6 +132,7 @@ CU_Test(ddsrt_getifaddrs, ipv6) CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); for (ifa = ifa_root; ifa; ifa = ifa->next) { CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); + assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET6); if (ifa->addr->sa_family == AF_INET6) { have_ipv6 = 1; @@ -170,6 +173,7 @@ CU_Test(ddsrt_getifaddrs, ipv4_n_ipv6) CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK); for (ifa = ifa_root; ifa; ifa = ifa->next) { CU_ASSERT_PTR_NOT_EQUAL_FATAL(ifa->addr, NULL); + assert (ifa->addr != NULL); /* for the benefit of clang's static analyzer */ CU_ASSERT(ifa->addr->sa_family == AF_INET || ifa->addr->sa_family == AF_INET6); if (ifa->addr->sa_family == AF_INET) { diff --git a/src/ddsrt/tests/log.c b/src/ddsrt/tests/log.c index 63c0438..36e3e1a 100644 --- a/src/ddsrt/tests/log.c +++ b/src/ddsrt/tests/log.c @@ -254,11 +254,8 @@ CU_Test(dds_log, no_sink, .init=setup, .fini=teardown) ptr = NULL; DDS_ERROR("foobaz\n"); ret = fseek(fh, 0, SEEK_SET); + CU_ASSERT_EQUAL_FATAL(ret, 0); CU_ASSERT_PTR_NULL(ptr); - if (ptr != NULL) { - ddsrt_free(ptr); - ptr = NULL; - } buf[0]= '\0'; cnt[1] = fread(buf, 1, sizeof(buf) - 1, fh); #ifdef _WIN32 diff --git a/src/ddsrt/tests/process_app.c b/src/ddsrt/tests/process_app.c index a0c402a..1613391 100644 --- a/src/ddsrt/tests/process_app.c +++ b/src/ddsrt/tests/process_app.c @@ -29,9 +29,13 @@ static int test_sleep(int argi, int argc, char **argv) argi++; if (argi < argc) { long long dorment; - ddsrt_strtoll(argv[argi], NULL, 0, &dorment); - printf(" Process: sleep %d seconds.\n", (int)dorment); - dds_sleepfor(DDS_SECS((int64_t)dorment)); + if (ddsrt_strtoll(argv[argi], NULL, 0, &dorment) != DDS_RETCODE_OK || dorment < 0 || dorment > INT32_MAX) { + printf(" Process: invalid --sleep argument.\n"); + return TEST_EXIT_WRONG_ARGS; + } else { + printf(" Process: sleep %d seconds.\n", (int)dorment); + dds_sleepfor(DDS_SECS((int64_t)dorment)); + } } else { printf(" Process: no --sleep value.\n"); return TEST_EXIT_WRONG_ARGS; diff --git a/src/mpt/tests/qos/procs/ppud.c b/src/mpt/tests/qos/procs/ppud.c index 25ae30a..0ac52f0 100644 --- a/src/mpt/tests/qos/procs/ppud.c +++ b/src/mpt/tests/qos/procs/ppud.c @@ -355,7 +355,7 @@ MPT_ProcessEntry (rwud, size_t chkusz = 0; if (!qget (chk, &chkud, &chkusz)) MPT_ASSERT (0, "Check QoS: no %s present\n", qname); - MPT_ASSERT (chkusz == expusz && (expusz == 0 || memcmp (chkud, expud, expusz) == 0), + MPT_ASSERT (chkusz == expusz && (expusz == 0 || (chkud != NULL && memcmp (chkud, expud, expusz) == 0)), "Retrieved %s differs from group data just set (%zu/%s vs %zu/%s)\n", qname, chkusz, chkud ? (char *) chkud : "(null)", expusz, expud ? (char *) expud : "(null)"); dds_free (chkud);