From 3f7bcfca9b72797db91263eaaf63a8f743e08ed7 Mon Sep 17 00:00:00 2001 From: Dennis Potman Date: Wed, 6 Sep 2023 13:28:01 +0200 Subject: [PATCH] Fixes for some build and static analyzer issues Signed-off-by: Dennis Potman --- src/core/ddsc/include/dds/ddsc/dds_psmx.h | 2 +- src/core/ddsc/src/dds__loaned_sample.h | 2 +- src/core/ddsc/src/dds__psmx.h | 2 +- src/core/ddsc/src/dds__qos.h | 2 +- src/core/ddsc/src/dds__writer.h | 5 +++-- src/core/ddsc/src/dds_heap_loan.c | 4 ++-- src/core/ddsc/src/dds_psmx.c | 16 ++++++++-------- src/core/ddsc/src/dds_write.c | 18 +++++++++++------- src/core/ddsi/tests/wraddrset.c | 12 ++++++------ 9 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/core/ddsc/include/dds/ddsc/dds_psmx.h b/src/core/ddsc/include/dds/ddsc/dds_psmx.h index cc6ac3004b..0da545e298 100644 --- a/src/core/ddsc/include/dds/ddsc/dds_psmx.h +++ b/src/core/ddsc/include/dds/ddsc/dds_psmx.h @@ -373,7 +373,7 @@ DDS_EXPORT dds_return_t dds_psmx_cleanup_generic (struct dds_psmx *psmx); * @param[in] topic_name the topic name * @return a DDS return code */ -DDS_EXPORT dds_return_t dds_psmx_topic_init_generic (struct dds_psmx_topic *topic, const struct dds_psmx *psmx, const char *topic_name); +DDS_EXPORT dds_return_t dds_psmx_topic_init_generic (struct dds_psmx_topic *psmx_topic, const struct dds_psmx *psmx, const char *topic_name); /** * @brief cleanup function for a topic diff --git a/src/core/ddsc/src/dds__loaned_sample.h b/src/core/ddsc/src/dds__loaned_sample.h index e5df2a0438..90ee2743ed 100644 --- a/src/core/ddsc/src/dds__loaned_sample.h +++ b/src/core/ddsc/src/dds__loaned_sample.h @@ -36,7 +36,7 @@ typedef struct dds_loan_pool dds_loan_pool_t; * @param[in] initial_cap Initial capacity * @return a DDS return code */ -dds_return_t dds_loan_pool_create (dds_loan_pool_t **pool, uint32_t initial_cap) +dds_return_t dds_loan_pool_create (dds_loan_pool_t **ppool, uint32_t initial_cap) ddsrt_nonnull_all; /** diff --git a/src/core/ddsc/src/dds__psmx.h b/src/core/ddsc/src/dds__psmx.h index bc31abcc72..3a98d7e91b 100644 --- a/src/core/ddsc/src/dds__psmx.h +++ b/src/core/ddsc/src/dds__psmx.h @@ -61,7 +61,7 @@ dds_return_t dds_endpoint_add_psmx_endpoint (struct dds_endpoint *ep, const dds_ void dds_endpoint_remove_psmx_endpoints (struct dds_endpoint *ep); struct ddsi_psmx_locators_set *dds_get_psmx_locators_set (const dds_qos_t *qos, const struct dds_psmx_set *psmx_instances); -void dds_psmx_locators_set_free (struct ddsi_psmx_locators_set *psmx_locators); +void dds_psmx_locators_set_free (struct ddsi_psmx_locators_set *psmx_locators_set); /** * @brief Request a loan diff --git a/src/core/ddsc/src/dds__qos.h b/src/core/ddsc/src/dds__qos.h index cdbd747c5d..85c27b610c 100644 --- a/src/core/ddsc/src/dds__qos.h +++ b/src/core/ddsc/src/dds__qos.h @@ -60,7 +60,7 @@ extern "C" { dds_return_t dds_ensure_valid_data_representation (dds_qos_t *qos, uint32_t allowed_data_representations, bool topicqos); /** @component qos_obj */ -dds_return_t dds_ensure_valid_psmx_instances (dds_qos_t *qos, dds_psmx_endpoint_type_t forwhat, ddsi_data_type_properties_t data_type_props, const struct dds_psmx_set *psmx_set); +dds_return_t dds_ensure_valid_psmx_instances (dds_qos_t *qos, dds_psmx_endpoint_type_t forwhat, ddsi_data_type_properties_t data_type_props, const struct dds_psmx_set *psmx_instances); /** @component qos_obj */ bool dds_qos_has_psmx_instances (const dds_qos_t *qos, const char *psmx_instance_name); diff --git a/src/core/ddsc/src/dds__writer.h b/src/core/ddsc/src/dds__writer.h index 7d5425c357..dfef0709ec 100644 --- a/src/core/ddsc/src/dds__writer.h +++ b/src/core/ddsc/src/dds__writer.h @@ -28,12 +28,13 @@ void dds_writer_status_cb (void *entity, const struct ddsi_status_cb_data * data void dds_writer_invoke_cbs_for_pending_events(struct dds_entity *e, uint32_t status); /** @component writer */ -dds_return_t dds_return_writer_loan(dds_writer *writer, void **buf, int32_t bufsz) ddsrt_nonnull_all; +dds_return_t dds_return_writer_loan (dds_writer *wr, void **samples_ptr, int32_t n_samples) ddsrt_nonnull_all; /** @component writer */ dds_return_t dds__ddsi_writer_wait_for_acks (struct dds_writer *wr, ddsi_guid_t *rdguid, dds_time_t abstimeout); -dds_return_t dds_request_writer_loan(dds_writer *wr, void **samples) +/** @component writer */ +dds_return_t dds_request_writer_loan (dds_writer *wr, void **sample) ddsrt_nonnull_all; #if defined (__cplusplus) diff --git a/src/core/ddsc/src/dds_heap_loan.c b/src/core/ddsc/src/dds_heap_loan.c index fcee990605..819a7b43f5 100644 --- a/src/core/ddsc/src/dds_heap_loan.c +++ b/src/core/ddsc/src/dds_heap_loan.c @@ -33,7 +33,7 @@ static void heap_loan_free (dds_loaned_sample_t *loaned_sample) ddsrt_free (hl); } -void dds_heap_loan_reset (dds_loaned_sample_t *loaned_sample) +void dds_heap_loan_reset (struct dds_loaned_sample *loaned_sample) { dds_heap_loan_t *hl = (dds_heap_loan_t *) loaned_sample; memset (hl->c.metadata, 0, sizeof (*(hl->c.metadata))); @@ -45,7 +45,7 @@ const dds_loaned_sample_ops_t dds_loan_heap_ops = { .free = heap_loan_free }; -dds_return_t dds_heap_loan (const struct ddsi_sertype *type, dds_loaned_sample_state_t sample_state, dds_loaned_sample_t **loaned_sample) +dds_return_t dds_heap_loan (const struct ddsi_sertype *type, dds_loaned_sample_state_t sample_state, struct dds_loaned_sample **loaned_sample) { assert (sample_state == DDS_LOANED_SAMPLE_STATE_RAW_KEY || sample_state == DDS_LOANED_SAMPLE_STATE_RAW_DATA); diff --git a/src/core/ddsc/src/dds_psmx.c b/src/core/ddsc/src/dds_psmx.c index 80b11e3e51..00ecf6c32c 100644 --- a/src/core/ddsc/src/dds_psmx.c +++ b/src/core/ddsc/src/dds_psmx.c @@ -25,16 +25,16 @@ static struct dds_psmx_endpoint * psmx_create_endpoint (struct dds_psmx_topic *psmx_topic, const struct dds_qos *qos, dds_psmx_endpoint_type_t endpoint_type); static dds_return_t psmx_delete_endpoint (struct dds_psmx_endpoint *psmx_endpoint); -dds_return_t dds_add_psmx_topic_to_list (struct dds_psmx_topic *topic, struct dds_psmx_topic_list_elem **list) +dds_return_t dds_add_psmx_topic_to_list (struct dds_psmx_topic *psmx_topic, struct dds_psmx_topic_list_elem **list) { - if (!topic) + if (!psmx_topic) return DDS_RETCODE_BAD_PARAMETER; struct dds_psmx_topic_list_elem *ptr = dds_alloc (sizeof (struct dds_psmx_topic_list_elem)); if (!ptr) return DDS_RETCODE_OUT_OF_RESOURCES; - ptr->topic = topic; + ptr->topic = psmx_topic; ptr->next = NULL; if (!*list) @@ -54,15 +54,15 @@ dds_return_t dds_add_psmx_topic_to_list (struct dds_psmx_topic *topic, struct dd return DDS_RETCODE_OK; } -dds_return_t dds_remove_psmx_topic_from_list (struct dds_psmx_topic *topic, struct dds_psmx_topic_list_elem **list) +dds_return_t dds_remove_psmx_topic_from_list (struct dds_psmx_topic *psmx_topic, struct dds_psmx_topic_list_elem **list) { - if (!topic || !list || !*list) + if (!psmx_topic || !list || !*list) return DDS_RETCODE_BAD_PARAMETER; dds_return_t ret = DDS_RETCODE_OK; struct dds_psmx_topic_list_elem *list_entry = *list; - while (list_entry && list_entry->topic != topic) + while (list_entry && list_entry->topic != psmx_topic) list_entry = list_entry->next; if (list_entry != NULL && (ret = list_entry->topic->psmx_instance->ops.delete_topic (list_entry->topic)) == DDS_RETCODE_OK) @@ -257,7 +257,7 @@ static int compare_psmx_prio (const void *va, const void *vb) return (psmx1->priority == psmx2->priority) ? 0 : ((psmx1->priority < psmx2->priority) ? 1 : -1); } -dds_return_t dds_pubsub_message_exchange_init (const struct ddsi_domaingv *gv, dds_domain *domain) +dds_return_t dds_pubsub_message_exchange_init (const struct ddsi_domaingv *gv, struct dds_domain *domain) { dds_return_t ret = DDS_RETCODE_OK; if (gv->config.psmx_instances != NULL) @@ -283,7 +283,7 @@ dds_return_t dds_pubsub_message_exchange_init (const struct ddsi_domaingv *gv, d return ret; } -dds_return_t dds_pubsub_message_exchange_fini (dds_domain *domain) +dds_return_t dds_pubsub_message_exchange_fini (struct dds_domain *domain) { dds_return_t ret = DDS_RETCODE_OK; for (uint32_t i = 0; ret == DDS_RETCODE_OK && i < domain->psmx_instances.length; i++) diff --git a/src/core/ddsc/src/dds_write.c b/src/core/ddsc/src/dds_write.c index 759c774e55..46bfbfcc11 100644 --- a/src/core/ddsc/src/dds_write.c +++ b/src/core/ddsc/src/dds_write.c @@ -384,16 +384,20 @@ dds_return_t dds_request_writer_loan (dds_writer *wr, void **sample) dds_loaned_sample_t *loan; if (wr->m_endpoint.psmx_endpoints.length > 0 && wr->m_topic->m_stype->fixed_size) - loan = dds_psmx_endpoint_request_loan (wr->m_endpoint.psmx_endpoints.endpoints[0], wr->m_topic->m_stype->zerocopy_size); + { + if ((loan = dds_psmx_endpoint_request_loan (wr->m_endpoint.psmx_endpoints.endpoints[0], wr->m_topic->m_stype->zerocopy_size)) == NULL) + ret = DDS_RETCODE_ERROR; + } else if ((ret = dds_heap_loan (wr->m_topic->m_stype, DDS_LOANED_SAMPLE_STATE_RAW_DATA, &loan)) != DDS_RETCODE_OK) loan = NULL; - if (loan == NULL) - ret = DDS_RETCODE_ERROR; - else if ((ret = dds_loan_pool_add_loan (wr->m_loans, loan)) != DDS_RETCODE_OK) - dds_loaned_sample_unref (loan); - else - *sample = loan->sample_ptr; + if (loan != NULL) + { + if ((ret = dds_loan_pool_add_loan (wr->m_loans, loan)) != DDS_RETCODE_OK) + dds_loaned_sample_unref (loan); + else + *sample = loan->sample_ptr; + } ddsrt_mutex_unlock (&wr->m_entity.m_mutex); return ret; } diff --git a/src/core/ddsi/tests/wraddrset.c b/src/core/ddsi/tests/wraddrset.c index eb15bb2def..85883d20e7 100644 --- a/src/core/ddsi/tests/wraddrset.c +++ b/src/core/ddsi/tests/wraddrset.c @@ -141,14 +141,14 @@ static void ddsi_wraddrset_some_cases (int casenumber, int cost, bool wr_psmx, c } const ddsi_plist_t plist_pp[4] = { PLIST_PP(0), PLIST_PP(1), PLIST_PP(2), PLIST_PP(3) }; ddsi_guid_t wrppguid, rdppguid[4][3]; - + setup_and_start (); ddsi_thread_state_awake (ddsi_lookup_thread_state(), &gv); ddsi_new_participant (&wrppguid, &gv, RTPS_PF_PRIVILEGED_PP | RTPS_PF_IS_DDSI2_PP, &plist_pp[0]); - + const struct ddsi_sertype st = { .ops = &(struct ddsi_sertype_ops){ .free = sertype_free }, - .serdata_ops = &(struct ddsi_serdata_ops){ }, + .serdata_ops = &(struct ddsi_serdata_ops){ NULL }, .serdata_basehash = 0, .typekind_no_key = 1, .request_keyhash = 0, @@ -161,7 +161,7 @@ static void ddsi_wraddrset_some_cases (int casenumber, int cost, bool wr_psmx, c .zerocopy_size = 8, .data_type_props = DDS_DATA_TYPE_IS_FIXED_SIZE }; - + struct ddsi_participant *pp = ddsi_entidx_lookup_participant_guid (gv.entity_index, &wrppguid); struct ddsi_writer *wr; ddsi_guid_t wrguid; @@ -176,7 +176,7 @@ static void ddsi_wraddrset_some_cases (int casenumber, int cost, bool wr_psmx, c }; ddsi_new_writer (&wr, &wrguid, NULL, pp, "Q", &st, &ddsi_default_qos_writer, &whc, NULL, NULL, wr_psmx ? &psmx_locs : NULL); assert (ddsi_entidx_lookup_writer_guid (gv.entity_index, &wrguid)); - + struct ddsi_tran_conn fake_conn = { .m_factory = ddsi_factory_find_supported_kind (&gv, DDSI_LOCATOR_KIND_PSMX), .m_interf = &(struct ddsi_network_interface){ @@ -224,7 +224,7 @@ static void ddsi_wraddrset_some_cases (int casenumber, int cost, bool wr_psmx, c ddsi_unref_addrset (rd_as); } } - + if (casenumber == 0) DDS_CLOG (DDS_LC_CONTENT, &gv.logconfig, " #rd/host cost: addresses\n"); DDS_CLOG (DDS_LC_CONTENT, &gv.logconfig, "%2d ", casenumber+1);