Skip to content

Commit

Permalink
Fix MISRA-RULE 11.1 (#1757)
Browse files Browse the repository at this point in the history
* Fix misra rule 11.1

* Resolve part of the MISRA-RULE-11.1

* Apply suggestion from PR.
  • Loading branch information
Splinter1984 authored Jul 24, 2023
1 parent a1ed0ff commit 8d120b9
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 73 deletions.
1 change: 1 addition & 0 deletions .github/codeql/resolved-misra-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ queries:
- uses: ./codeql-coding-standards/c/misra/src/rules/RULE-22-8/ErrnoSetToZeroPriorToCall.ql
- uses: ./codeql-coding-standards/c/misra/src/rules/RULE-8-3/DeclarationsOfAFunctionSameNameAndType.ql #[1/2]
# - uses: ./codeql-coding-standards/c/misra/src/rules/RULE-8-3/DeclarationsOfAnObjectSameNameAndType.ql #[2/2]
# - uses: ./codeql-coding-standards/c/misra/src/rules/RULE-11-1/ConversionBetweenFunctionPointerAndOtherType.ql
2 changes: 1 addition & 1 deletion src/core/ddsc/src/dds__entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ union dds_status_union {
struct dds_listener const * const listener = &e->m_entity.m_listener; \
update_##name_ (&e->m_##name_##_status, data); \
bool signal; \
if (listener->on_##name_ == 0) \
if (listener->on_##name_ == NULL) \
signal = dds_entity_status_set (&e->m_entity, DDS_##NAME_##_STATUS); \
else \
signal = status_cb_##name_##_invoke (e); \
Expand Down
2 changes: 1 addition & 1 deletion src/core/ddsc/src/dds_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int dds_domain_compare (const void *va, const void *vb)
}

static const ddsrt_avl_treedef_t dds_domaintree_def = DDSRT_AVL_TREEDEF_INITIALIZER (
offsetof (dds_domain, m_node), offsetof (dds_domain, m_id), dds_domain_compare, 0);
offsetof (dds_domain, m_node), offsetof (dds_domain, m_id), dds_domain_compare, NULL);

struct config_source {
enum { CFGKIND_XML, CFGKIND_RAW } kind;
Expand Down
6 changes: 3 additions & 3 deletions src/core/ddsc/src/dds_dynamic_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,12 @@ static dds_return_t set_member_bool_prop (dds_dynamic_type_t *type, uint32_t mem

dds_return_t dds_dynamic_member_set_key (dds_dynamic_type_t *type, uint32_t member_id, bool is_key)
{
return (type->ret = set_member_bool_prop (type, member_id, is_key, ddsi_dynamic_type_member_set_key, 0));
return (type->ret = set_member_bool_prop (type, member_id, is_key, ddsi_dynamic_type_member_set_key, NULL));
}

dds_return_t dds_dynamic_member_set_optional (dds_dynamic_type_t *type, uint32_t member_id, bool is_optional)
{
return (type->ret = set_member_bool_prop (type, member_id, is_optional, ddsi_dynamic_type_member_set_optional, 0));
return (type->ret = set_member_bool_prop (type, member_id, is_optional, ddsi_dynamic_type_member_set_optional, NULL));
}

dds_return_t dds_dynamic_member_set_external (dds_dynamic_type_t *type, uint32_t member_id, bool is_external)
Expand Down Expand Up @@ -532,7 +532,7 @@ dds_return_t dds_dynamic_member_set_hashid (dds_dynamic_type_t *type, uint32_t m

dds_return_t dds_dynamic_member_set_must_understand (dds_dynamic_type_t *type, uint32_t member_id, bool is_must_understand)
{
return (type->ret = set_member_bool_prop (type, member_id, is_must_understand, ddsi_dynamic_type_member_set_must_understand, 0));
return (type->ret = set_member_bool_prop (type, member_id, is_must_understand, ddsi_dynamic_type_member_set_must_understand, NULL));
}

dds_return_t dds_dynamic_type_register (dds_dynamic_type_t *type, struct ddsi_typeinfo **type_info)
Expand Down
6 changes: 3 additions & 3 deletions src/core/ddsc/src/dds_entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static int compare_instance_handle (const void *va, const void *vb)
return (*a == *b) ? 0 : (*a < *b) ? -1 : 1;
}

const ddsrt_avl_treedef_t dds_entity_children_td = DDSRT_AVL_TREEDEF_INITIALIZER (offsetof (struct dds_entity, m_avlnode_child), offsetof (struct dds_entity, m_iid), compare_instance_handle, 0);
const ddsrt_avl_treedef_t dds_entity_children_td = DDSRT_AVL_TREEDEF_INITIALIZER (offsetof (struct dds_entity, m_avlnode_child), offsetof (struct dds_entity, m_iid), compare_instance_handle, NULL);

static void dds_entity_observers_signal_delete (dds_entity *observed);

Expand Down Expand Up @@ -268,7 +268,7 @@ dds_entity_t dds_entity_init (dds_entity *e, dds_entity *parent, dds_entity_kind

/* Special case: the on_data_on_readers event doesn't exist on DataReaders. */
if (kind == DDS_KIND_READER)
e->m_listener.on_data_on_readers = 0;
e->m_listener.on_data_on_readers = NULL;

if (parent)
{
Expand Down Expand Up @@ -1054,7 +1054,7 @@ dds_return_t dds_set_listener (dds_entity_t entity, const dds_listener_t *listen

/* Special case: the on_data_on_readers event doesn't exist on DataReaders. */
if (dds_entity_kind (e) == DDS_KIND_READER)
e->m_listener.on_data_on_readers = 0;
e->m_listener.on_data_on_readers = NULL;

x = e;
while (dds_entity_kind (x) != DDS_KIND_CYCLONEDDS)
Expand Down
29 changes: 14 additions & 15 deletions src/core/ddsc/src/dds_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,26 @@ void dds_delete_listener (dds_listener_t * __restrict listener)
{
dds_free (listener);
}

void dds_reset_listener (dds_listener_t * __restrict listener)
{
if (listener)
{
dds_listener_t * const l = listener;
l->inherited = 0;
l->reset_on_invoke = 0;
l->on_data_available = 0;
l->on_data_on_readers = 0;
l->on_inconsistent_topic = 0;
l->on_liveliness_changed = 0;
l->on_liveliness_lost = 0;
l->on_offered_deadline_missed = 0;
l->on_offered_incompatible_qos = 0;
l->on_publication_matched = 0;
l->on_requested_deadline_missed = 0;
l->on_requested_incompatible_qos = 0;
l->on_sample_lost = 0;
l->on_sample_rejected = 0;
l->on_subscription_matched = 0;
l->on_data_available = NULL;
l->on_data_on_readers = NULL;
l->on_inconsistent_topic = NULL;
l->on_liveliness_changed = NULL;
l->on_liveliness_lost = NULL;
l->on_offered_deadline_missed = NULL;
l->on_offered_incompatible_qos = NULL;
l->on_publication_matched = NULL;
l->on_requested_deadline_missed = NULL;
l->on_requested_incompatible_qos = NULL;
l->on_sample_lost = NULL;
l->on_sample_rejected = NULL;
l->on_subscription_matched = NULL;
}
}

Expand All @@ -70,7 +69,7 @@ void dds_copy_listener (dds_listener_t * __restrict dst, const dds_listener_t *
static bool dds_combine_listener_merge (uint32_t inherited, void (*dst)(void), void (*src)(void))
{
(void)inherited;
return dst == 0 && src != 0;
return dst == NULL && src != NULL;
}

static bool dds_combine_listener_override_inherited (uint32_t inherited, void (*dst)(void), void (*src)(void))
Expand Down
2 changes: 1 addition & 1 deletion src/core/ddsc/src/dds_participant.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static int cmp_ktopic_name (const void *a, const void *b)
return strcmp (a, b);
}

const ddsrt_avl_treedef_t participant_ktopics_treedef = DDSRT_AVL_TREEDEF_INITIALIZER_INDKEY(offsetof (struct dds_ktopic, pp_ktopics_avlnode), offsetof (struct dds_ktopic, name), cmp_ktopic_name, 0);
const ddsrt_avl_treedef_t participant_ktopics_treedef = DDSRT_AVL_TREEDEF_INITIALIZER_INDKEY(offsetof (struct dds_ktopic, pp_ktopics_avlnode), offsetof (struct dds_ktopic, name), cmp_ktopic_name, NULL);

static dds_return_t dds_participant_status_validate (uint32_t mask)
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/ddsc/src/dds_readcond.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dds_entity_t dds_create_readcondition (dds_entity_t reader, uint32_t mask)
else
{
dds_entity_t hdl;
dds_readcond *cond = dds_create_readcond_impl (rd, DDS_KIND_COND_READ, mask, 0);
dds_readcond *cond = dds_create_readcond_impl (rd, DDS_KIND_COND_READ, mask, NULL);
assert (cond);
hdl = cond->m_entity.m_hdllink.hdl;
dds_entity_init_complete (&cond->m_entity);
Expand Down
2 changes: 1 addition & 1 deletion src/core/ddsc/src/dds_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void dds_reader_data_available_cb (struct dds_reader *rd)

ddsrt_mutex_lock (&rd->m_entity.m_observers_lock);
const uint32_t status_and_mask = ddsrt_atomic_ld32 (&rd->m_entity.m_status.m_status_and_mask);
if (lst->on_data_on_readers == 0 && lst->on_data_available == 0)
if (lst->on_data_on_readers == NULL && lst->on_data_available == NULL)
signal = data_avail_cb_set_status (&rd->m_entity, status_and_mask);
else
{
Expand Down
8 changes: 4 additions & 4 deletions src/core/ddsc/src/dds_rhc_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ static bool add_sample (struct dds_rhc_default *rhc, struct rhc_instance *inst,
if (rhc->nqconds != 0)
{
for (dds_readcond *rc = rhc->conds; rc != NULL; rc = rc->m_next)
if (rc->m_query.m_filter != 0 && eval_predicate_sample (rhc, s->sample, rc->m_query.m_filter))
if (rc->m_query.m_filter != NULL && eval_predicate_sample (rhc, s->sample, rc->m_query.m_filter))
s->conds |= rc->m_query.m_qcmask;
}

Expand Down Expand Up @@ -2384,7 +2384,7 @@ static bool dds_rhc_default_add_readcondition (struct dds_rhc *rhc_common, dds_r
ddsrt_mutex_lock (&rhc->lock);

/* Allocate a slot in the condition bitmasks; return an error no more slots are available */
if (cond->m_query.m_filter != 0)
if (cond->m_query.m_filter != NULL)
{
dds_querycond_mask_t avail_qcmask = ~(dds_querycond_mask_t)0;
for (dds_readcond *rc = rhc->conds; rc != NULL; rc = rc->m_next)
Expand All @@ -2408,7 +2408,7 @@ static bool dds_rhc_default_add_readcondition (struct dds_rhc *rhc_common, dds_r
rhc->conds = cond;

uint32_t trigger = 0;
if (cond->m_query.m_filter == 0)
if (cond->m_query.m_filter == NULL)
{
/* Read condition is not cached inside the instances and samples, so it only needs
to be evaluated on the non-empty instances */
Expand Down Expand Up @@ -2555,7 +2555,7 @@ static bool update_conditions_locked (struct dds_rhc_default *rhc, bool called_f
}

TRACE (" cond %p %08"PRIx32": ", (void *) iter, iter->m_query.m_qcmask);
if (iter->m_query.m_filter == 0)
if (iter->m_query.m_filter == NULL)
{
assert (dds_entity_kind (&iter->m_entity) == DDS_KIND_COND_READ);
if (m_pre == m_post)
Expand Down
16 changes: 8 additions & 8 deletions src/core/ddsc/src/dds_serdata_builtintopic.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ const struct ddsi_serdata_ops ddsi_serdata_ops_builtintopic = {
.get_size = serdata_builtin_get_size,
.eqkey = serdata_builtin_eqkey,
.free = serdata_builtin_free,
.from_ser = 0,
.from_ser_iov = 0,
.from_keyhash = 0,
.from_ser = NULL,
.from_ser_iov = NULL,
.from_keyhash = NULL,
.from_sample = ddsi_serdata_builtin_from_sample,
.to_ser = serdata_builtin_to_ser,
.to_sample = serdata_builtin_to_sample,
Expand All @@ -443,7 +443,7 @@ const struct ddsi_serdata_ops ddsi_serdata_ops_builtintopic = {
.to_untyped = serdata_builtin_to_untyped,
.untyped_to_sample = serdata_builtin_untyped_to_sample,
.print = serdata_builtin_type_print,
.get_keyhash = 0
.get_keyhash =NULL
};

#ifdef DDS_HAS_TOPIC_DISCOVERY
Expand Down Expand Up @@ -487,9 +487,9 @@ const struct ddsi_serdata_ops ddsi_serdata_ops_builtintopic_topic = {
.get_size = serdata_builtin_get_size,
.eqkey = serdata_builtin_eqkey,
.free = serdata_builtin_free,
.from_ser = 0,
.from_ser_iov = 0,
.from_keyhash = 0,
.from_ser = NULL,
.from_ser_iov = NULL,
.from_keyhash = NULL,
.from_sample = ddsi_serdata_builtin_from_sample_topic,
.to_ser = serdata_builtin_to_ser,
.to_sample = serdata_builtin_to_sample,
Expand All @@ -498,7 +498,7 @@ const struct ddsi_serdata_ops ddsi_serdata_ops_builtintopic_topic = {
.to_untyped = serdata_builtin_to_untyped,
.untyped_to_sample = serdata_builtin_untyped_to_sample,
.print = serdata_builtin_type_print,
.get_keyhash = 0
.get_keyhash =NULL
};

#endif /* DDS_HAS_TOPIC_DISCOVERY */
12 changes: 6 additions & 6 deletions src/core/ddsc/src/dds_sertype_builtintopic.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static void sertype_builtin_free_samples (const struct ddsi_sertype *sertype_com
#endif
if (op & DDS_FREE_CONTENTS_BIT)
{
void (*f) (void *a) = 0;
void (*f) (void *a) = NULL;
char *ptr = ptrs[0];
switch (tp->entity_kind)
{
Expand Down Expand Up @@ -185,9 +185,9 @@ const struct ddsi_sertype_ops ddsi_sertype_ops_builtintopic = {
.zero_samples = sertype_builtin_zero_samples,
.realloc_samples = sertype_builtin_realloc_samples,
.free_samples = sertype_builtin_free_samples,
.type_id = 0,
.type_map = 0,
.type_info = 0,
.get_serialized_size = 0,
.serialize_into = 0
.type_id = NULL,
.type_map = NULL,
.type_info = NULL,
.get_serialized_size = NULL,
.serialize_into =NULL
};
4 changes: 2 additions & 2 deletions src/core/ddsc/src/dds_topic.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ dds_return_t dds_set_topic_filter_extended (dds_entity_t topic, const struct dds
case DDS_TOPIC_FILTER_NONE:
// treat function and argument as don't cares on input if mode = NONE, but
// do make them null pointers in the internal representation
f.f.sample = 0;
f.f.sample = NULL;
f.arg = NULL;
valid = true;
break;
Expand All @@ -942,7 +942,7 @@ dds_return_t dds_set_topic_filter_extended (dds_entity_t topic, const struct dds
case DDS_TOPIC_FILTER_SAMPLE_ARG:
case DDS_TOPIC_FILTER_SAMPLE_SAMPLEINFO_ARG:
// can safely use any of the function pointers
valid = (filter->f.sample != 0);
valid = (filter->f.sample != NULL);
break;
}
if (!valid)
Expand Down
2 changes: 1 addition & 1 deletion src/core/ddsc/src/dds_whc.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static bool whc_default_sample_iter_borrow_next (struct ddsi_whc_sample_iter *op
static void whc_default_free (struct ddsi_whc *whc_generic);

static const ddsrt_avl_treedef_t whc_seq_treedef =
DDSRT_AVL_TREEDEF_INITIALIZER (offsetof (struct whc_intvnode, avlnode), offsetof (struct whc_intvnode, min), compare_seq, 0);
DDSRT_AVL_TREEDEF_INITIALIZER (offsetof (struct whc_intvnode, avlnode), offsetof (struct whc_intvnode, min), compare_seq, NULL);

static const struct ddsi_whc_ops whc_ops = {
.insert = whc_default_insert,
Expand Down
8 changes: 4 additions & 4 deletions src/core/ddsc/src/dds_whc_builtintopic.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ static const struct ddsi_whc_ops bwhc_ops = {
.remove_acked_messages = bwhc_remove_acked_messages,
.free_deferred_free_list = bwhc_free_deferred_free_list,
.get_state = bwhc_get_state,
.next_seq = 0,
.borrow_sample = 0,
.borrow_sample_key = 0,
.return_sample = 0,
.next_seq = NULL,
.borrow_sample = NULL,
.borrow_sample_key = NULL,
.return_sample = NULL,
.sample_iter_init = bwhc_sample_iter_init,
.sample_iter_borrow_next = bwhc_sample_iter_borrow_next,
.free = bwhc_free
Expand Down
12 changes: 6 additions & 6 deletions src/core/ddsi/src/ddsi_addrset.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ struct addrset_forall_helper_arg
void * arg;
};

static void addrset_forall_helper (void *vnode, void *varg)
static void addrset_forall_helper (const void *vnode, void *varg)
{
const struct ddsi_addrset_node *n = vnode;
struct addrset_forall_helper_arg *arg = varg;
Expand All @@ -564,8 +564,8 @@ size_t ddsi_addrset_forall_count (struct ddsi_addrset *as, ddsi_addrset_forall_f
arg1.f = f;
arg1.arg = arg;
LOCK (as);
ddsrt_avl_cwalk (&addrset_treedef, &as->mcaddrs, addrset_forall_helper, &arg1);
ddsrt_avl_cwalk (&addrset_treedef, &as->ucaddrs, addrset_forall_helper, &arg1);
ddsrt_avl_cconst_walk (&addrset_treedef, &as->mcaddrs, addrset_forall_helper, &arg1);
ddsrt_avl_cconst_walk (&addrset_treedef, &as->ucaddrs, addrset_forall_helper, &arg1);
count = ddsrt_avl_ccount (&as->ucaddrs) + ddsrt_avl_ccount (&as->mcaddrs);
UNLOCK (as);
return count;
Expand All @@ -585,12 +585,12 @@ size_t ddsi_addrset_forall_uc_else_mc_count (struct ddsi_addrset *as, ddsi_addrs
LOCK (as);
if (!ddsrt_avl_cis_empty (&as->ucaddrs))
{
ddsrt_avl_cwalk (&addrset_treedef, &as->ucaddrs, addrset_forall_helper, &arg1);
ddsrt_avl_cconst_walk (&addrset_treedef, &as->ucaddrs, addrset_forall_helper, &arg1);
count = ddsrt_avl_ccount (&as->ucaddrs);
}
else
{
ddsrt_avl_cwalk (&addrset_treedef, &as->mcaddrs, addrset_forall_helper, &arg1);
ddsrt_avl_cconst_walk (&addrset_treedef, &as->mcaddrs, addrset_forall_helper, &arg1);
count = ddsrt_avl_ccount (&as->mcaddrs);
}
UNLOCK (as);
Expand All @@ -604,7 +604,7 @@ size_t ddsi_addrset_forall_mc_count (struct ddsi_addrset *as, ddsi_addrset_foral
arg1.f = f;
arg1.arg = arg;
LOCK (as);
ddsrt_avl_cwalk (&addrset_treedef, &as->mcaddrs, addrset_forall_helper, &arg1);
ddsrt_avl_cconst_walk (&addrset_treedef, &as->mcaddrs, addrset_forall_helper, &arg1);
count = ddsrt_avl_ccount (&as->mcaddrs);
UNLOCK (as);
return count;
Expand Down
4 changes: 2 additions & 2 deletions src/core/ddsi/tests/sysdeps.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static ddsrt_avl_tree_t helper_tree = {
&helper_node.avlnode
};

static void log_stacktrace_helper (void *vnode, void *varg)
static void log_stacktrace_helper (const void *vnode, void *varg)
{
struct log_stacktrace_thread_arg * const arg = varg;
(void) vnode;
Expand All @@ -176,7 +176,7 @@ static void log_stacktrace_helper (void *vnode, void *varg)

static uint32_t log_stacktrace_thread (void *varg)
{
ddsrt_avl_walk (&helper_treedef, &helper_tree, log_stacktrace_helper, varg);
ddsrt_avl_const_walk (&helper_treedef, &helper_tree, log_stacktrace_helper, varg);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ddsrt/src/avl.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static ddsrt_avl_node_t *rebalance_one (const ddsrt_avl_treedef_t *td, ddsrt_avl
way up to the root even when not needed for the rebalancing
itself. */
int height = (height_L < height_R ? height_R : height_L) + 1;
if (td->augment == 0 && height == node->height) {
if (td->augment == NULL && height == node->height) {
return NULL;
} else {
node->height = height;
Expand Down
Loading

0 comments on commit 8d120b9

Please sign in to comment.