-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: enforcing MISRA compliant Boolean values #7110
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Ansh Goyal <anshgoyal1704@gmail.com>
damn, I'm too slow. Anyway, shouldn't this go into addons/misra.py ? I would guess Rule 23.6 |
Thanks for the suggestion, @okias. I am fairly new to this MISRA thing. I just read the discussion in the thread commaai/panda#1876 and this way looked like what adding the check into ustream meant. Can you please help identify if that's the right way to do that? Adding a check into upstream without explicitly defining an addon code. |
In general, a C++ solution like the one you wrote looks better, but I understood it as part of the MISRA plugin—something like this: okias@6b3d84a. The code doesn't detect the initial |
Thanks. Now I get the point. I would implement it the MISRA plugin way if this one is rejected by the maintainers. |
Hi, sorry for the late review. I spontanously feel this might be too "stylistic" in nature. It's not to find "buggy" code, is it? What bugs could it lead to? Normally I like if "style" checkers have a motivation to prevent some possible bugs. For instance; unread variables can for instance indicate an overlook. I wouldn't normally write In my humble opinion it does not violate MISRA 23.6 but it does violate 10.3 and Cppcheck Premium writes a warning about it. |
The implementation: I don't have major complaints. It's pretty good. But some test cases is needed and also I think a ticket should be added in trac and the release notes would need to mention the new checker.. |
Thanks for the inputs. This would not help prevent bugs to the code but would help increase readability at some places. I would add the required test cases. Can you please elaborate that trac thing. How can I file a ticket out there? |
well.. I don't know why anybody would WANT to do this.. but still I don't have a very good feeling about this. This is not the high prio findings users want to see. Could you try to write a checker that looks for "mistakes" somehow? I believe trac has many suggestions as inspiration. to get an account on trac you'll need to send a htpasswd hash to me. You can generate a htpasswd hash online, google "htpasswd hash generator" |
This looks to be MISRA 10.x territory. |
Checked the Misra Plugin and currently it is checked here if a bool gets assigned a value bigger than 0 or 1 Lines 2328 to 2329 in 85423bd
And additionally i checked your code against the Warnings 10.3 was found for
and the following was false negative:
This is because the Essential Type Line 543 in 85423bd
{NULL} as well as &bnull_f is not handled here and returns None at the end of the function, even if they have a valueType assigned to them. Similar is true for the keywords true and false they both have a value type assigned to them in the dump file but they both also return None from the Essential Type function and therefore the check stops due to one of the sides having a None Type.
And maybe i am tripping but seeing https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/tools/-/blob/main/misra_c_2012__headlines_for_cppcheck%20-%20AMD1+AMD2.txt?ref_type=heads#L180 |
if you change misra.py rule 10.3 so that it warns I am not against it. |
I have the feeling that C89 does not have a "bool" type. And one possible way to use bools would be:
my guess this is why misra.py is written as it is. |
Actually true 🤔 stdbool was added in C99. Maybe dependent on Code Standard for C89 allow 0 and 1 and for C99 not? |
Sounds good to me. |
This PR adds a literal to boolean style check.
ref: commaai/panda#1876, commaai/panda#2105