how to configure Polyspace to enforce const qualifiers?

23 visualizzazioni (ultimi 30 giorni)
Ilya
Ilya il 28 Ott 2025 alle 0:27
Commentato: Ilya il 30 Ott 2025 alle 22:25
We use Polyspace 2023b.
Is there a check that could be done to enforce const qualifiers in functions? For example: a parameter passed as a pointer, but the pointer is never changed inside. How to configure Polyspace to flag this to set the pointer to const.

Risposta accettata

Soumya
Soumya il 30 Ott 2025 alle 6:48
Hi @Ilya,
Yes, in Polyspace Bug Finder 2023b, there is a way to flag cases where a pointer parameter could be declared 'const' if it is not modified inside a function. This is supported through MISRA C:2023 Rule 8.13, which states that a pointer should point to a const-qualified type whenever possible.
To enable this check:
  • Make sure your analysis is configured to use the MISRA C:2023 coding standard.
  • Confirm that Rule 8.13 is active in your rule set. Polyspace will then analyze whether pointer parameters are used to modify the data they point to. If not, it will flag the parameter as a candidate for const qualification.
Please note that this rule is context-sensitive. For example, if a pointer parameter is copied and later modified indirectly, Polyspace may not report it. Additionally, this rule is designed to address coding-standard compliance rather than stylistic recommendations, so it will not enforce const propagation beyond what is explicitly defined in the selected standard.
If you are not using MISRA C:2023 or need broader enforcement, you could supplement Polyspace with external tools like Clang-Tidy or integrate const-qualification checks into your code review process.
For more details, refer to the official documentation:
I hope this helps!

Più risposte (0)

Prodotti


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by