-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix #13615: False positive: Misra C 17.3: UINT32_C #7276
base: main
Are you sure you want to change the base?
Conversation
FYI We used to replace these macros but they were removed a while ago and need to be re-added. |
@firewave we need to keep UINT32_C in some way for misra. For instance the code The Misra checker for rule 7.5 could in theory use the "raw tokens" instead but that means that violations in headers are not detected and there could also be false negatives when macros is used. So for the sake of Misra I would suggest that we don't replace UINT32_C. Or do you think there is some better replacement that will still mean we can detect misra violations properly? |
I am saying that if we would add something like this:
Then the dumpfile will not contain the necessary information. If the code is |
Right because those are just replacements and are not treated as macros. Maybe that should be changed. But as you noted in the past |
I am not sure how to implement that. How about this define:
If the code says |
It should no different from the existing defines we already generate. But these should be flagged as non-internal ones. That is a feature we need to implement in simplecpp first. And it is probably not important. |
Shouldn’t the macro simply be added to C99_STDLIB_IDENTIFIERS under stdint.h? At least this side claims it is since C99 https://en.cppreference.com/w/c/types/integer. Especially as Then Misra will not complain as 17.3 checks isStdLibId and it will then return that this is a known std lib macro. And actually checking https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf Appendix B.17 as referenced in the code there might be a missunderstanding (bug) in the first place. The list C99_STDLIB_IDENTIFIERS mentions
|
I added a PR which updates the list of std library identifiers. #7325 which should fix this issue in the way all other cases where handled before. And is based on the C standard automatically (meaning C89 where these are not present get an error above C99 we don’t get the error). |
That sounds better to me. However one more detail is that Cppcheck now does not manage to determine the value of expression
The cast macro I showed earlier would solve this problem but I am afraid that the cast macro I showed will not be able to distinguish C89/C99/etc..
Thanks! |
I am not sure if this is in line with your goals but C89 does not have the UINT32_C macro so C89 code with this Makro in it shouldn’t compile. I am not sure if the harm would be so big with C89? Especially as you could argue for Misra all define/makros which are caught by this rule are false positives as they are not a function. Putting them into the StdLibIds is only necessary because they are not resolved by the preprocessor in the first place. But I would need to double check what happens in the dump file exactly for defines to maybe add other suggestions. |
The problem is not specific to the But in that case we would defiantly need this: https://trac.cppcheck.net/ticket/12359 |
I think the actual problem is https://trac.cppcheck.net/ticket/13341. |
No description provided.