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

tests: Made pointer parameters explicitely const where non-const pointer parameters are not needed #72417

Conversation

DeHess
Copy link
Collaborator

@DeHess DeHess commented May 7, 2024

modified parameter types to receive a const pointer when a non-const pointer is not needed

This corresponds to following misra coding guideline:

A cast shall not remove any const or volatile qualification from the type pointed to by a pointer

This PR is part of the enhancement issue #48002 which port the coding guideline fixes done by BUGSENG on the https://github.com/zephyrproject-rtos/zephyr/tree/v2.7-auditable-branch back to main

The commit in this PR is a subset of the original auditable-branch commit:
f953e92

@DeHess DeHess marked this pull request as draft May 7, 2024 14:54
@DeHess DeHess force-pushed the misra_rule_11_8_auditable_to_main_tests branch 2 times, most recently from 6960f1a to 08c5b8b Compare May 13, 2024 06:56
@DeHess DeHess marked this pull request as ready for review May 13, 2024 09:04
@npitre
Copy link
Collaborator

npitre commented May 13, 2024

You changed:

-       zassert_true(arch_buffer_validate((void *)&__ramfunc_start,
+       zassert_true(arch_buffer_validate((const void *)&__ramfunc_start,

How this can even not produce a warning given that arch_buffer_validate()
is declared with a plain (not const) void pointer? Maybe it is
arch_buffer_validate() that ought to qualify its argument as const as
it is not supposed to alter the buffer's content.

Also the original cast is probably redundant and could be removed
altogether.

Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

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

Let's not do const-correctness piecewise. Const goes on function arguments and struct fields first, then propagates outwards as needed. Declaring local variables const is at best providing some tiny bit of safety in a single function, and as @npitre points out the cast on that pointer is just a noop as the argument is non-const.

- modified parameter types to receive a const pointer when a
  non-const pointer is not needed

Signed-off-by: Hess Nathan <nhess@baumer.com>
@DeHess DeHess force-pushed the misra_rule_11_8_auditable_to_main_tests branch from 08c5b8b to 695ae33 Compare May 17, 2024 06:58
@zephyrbot zephyrbot added the Trivial Changes that can be reviewed by anyone, i.e. doc changes, minor build system tweaks, etc. label May 17, 2024
@DeHess
Copy link
Collaborator Author

DeHess commented May 17, 2024

@andyross , @npitre

You are right, i was planning on adding const thing seperately across the different modules of the project.

I admit it was never ideal.

As it turns out, it might be possible to remove the arch_buffer_validate method entirely, as it does not seem to be in use anymore.
For this pr, I just removed the change for the validate method.

@DeHess DeHess requested a review from andyross May 17, 2024 07:02
Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

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

Still seems silly to have a whole PR just to flag one local variable const in a random test, but no reason not to approve I guess.

@nashif nashif added the area: Coding Guidelines Coding guidelines and style label May 27, 2024
@nashif nashif merged commit 209a3bd into zephyrproject-rtos:main Jun 3, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Architectures area: Coding Guidelines Coding guidelines and style area: Device Model area: Kernel Trivial Changes that can be reviewed by anyone, i.e. doc changes, minor build system tweaks, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants