Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misrac: Checking the returned value of a non-void function #18344

Closed
wants to merge 1 commit into from

Conversation

ceolin
Copy link
Member

@ceolin ceolin commented Aug 16, 2019

MISRA-C rule 17.7 says that the return value of a non-void must be
checked. For memcpy/memset there is no error handling or checking we
can do with the return value, so it is just casting it to void to
explicitly ignore while adhering to MISRA-C.

This patch was generated using the coccinelle script
ignore_return.cocci

Signed-off-by: Flavio Ceolin [email protected]

MISRA-C rule 17.7 says that the return value of a non-void must be
checked. For memcpy/memset there is no error handling or checking we
can do with the return value, so it is just casting it to void to
explicitly ignore while adhering to MISRA-C.

This patch was generated using the coccinelle script
ignore_return.cocci

Signed-off-by: Flavio Ceolin <[email protected]>
@pabigot
Copy link
Collaborator

pabigot commented Aug 17, 2019

17.7 is a required rule, which allows deviations. A reasonable deviation is that when the return value is a constant that cannot affect control flow, as it is with mem*, there is no need to explicitly indicate that it is being ignored.

@pabigot pabigot mentioned this pull request Aug 17, 2019
@ceolin
Copy link
Member Author

ceolin commented Aug 18, 2019

17.7 is a required rule, which allows deviations. A reasonable deviation is that when the return value is a constant that cannot affect control flow, as it is with mem*, there is no need to explicitly indicate that it is being ignored.

I know that, I'm imagining if we start create deviation for this simple case we'll end up with deviations for almost all rules, honestly. People will be much more sensitive to other cases. Is that what we want, deviate from every single rule ?

@pfalcon pfalcon removed their request for review November 1, 2019 09:19
@pabigot
Copy link
Collaborator

pabigot commented Nov 21, 2019

Regardless of how this rule is applied, I would really appreciate it if Coccinelle fixes were applied in two stages: first a single commit that adds the SmPL script (possibly in scripts/coccinelle/misra or .../codingrules, or...). Then a commit that applies the script.

Not having access to the scripts that perform the rewrite makes it harder for people to verify they aren't introducing new violations, let alone integrate checks into any sort of QA process.

@dleach02 dleach02 modified the milestones: v2.1.0, v2.2.0 Dec 3, 2019
@galak galak removed this from the v2.2.0 milestone Feb 12, 2020
@dleach02
Copy link
Member

@ceolin Do you intend to continuing pursing this PR to merge?

@dleach02 dleach02 added the Waiting for response Waiting for author's response label Jun 16, 2020
@github-actions github-actions bot added area: ARM ARM (32-bit) Architecture area: native port Host native arch port (native_sim) has-conflicts Issue/PR has conflicts with another issue/PR and removed has-conflicts Issue/PR has conflicts with another issue/PR labels Jun 29, 2020
@@ -260,18 +260,18 @@ static int bt_ipm_send(struct net_buf *buf)
buf->len);
k_sem_take(&acl_data_ack, K_FOREVER);
net_buf_push_u8(buf, HCI_ACL);
memcpy((void *)
(void)memcpy((void *)
&((TL_AclDataPacket_t *)HciAclDataBuffer)->AclDataSerial,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be re-indented.

memcpy(&attr, &static_svc->attrs[i],
sizeof(attr));
(void)memcpy(&attr, &static_svc->attrs[i],
sizeof(attr));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT the alignment is still off. How much effort should we put into this if we cannot do it with a script? It's almost 250 files and the PR has been up for a while.

@ceolin
Copy link
Member Author

ceolin commented Aug 24, 2020

Will close this outdated patch and re-open a new one later.

@ceolin ceolin closed this Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ARM ARM (32-bit) Architecture area: MISRA-C area: native port Host native arch port (native_sim) has-conflicts Issue/PR has conflicts with another issue/PR platform: NXP NXP platform: Silabs Silicon Labs platform: STM32 ST Micro STM32 Waiting for response Waiting for author's response
Projects
None yet
Development

Successfully merging this pull request may close these issues.