The checker for MISRA rule 4.1 works fine for compliant and non-compliant examples part of MISRA 2012 document. However if the hexadecimal and octal escape sequences are not of full length (\x + 2 hex digits or \ + 3 octal digits) than the checker generates false positives. The following lines generate false positives but from my point of view they are compliant. The last one leads to an out of range exception and terminates the MISRA python addon.
?
Otherwise the multi-character character constant seems to have implementation defined behaviour and is not forbidden in C. So this could also be used as an example throwing some warning (maybe not 4.1).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
MISRA rule 4.1 states int c41_4 = '\141\t'; as compliant and the above lines just use less than 3 octal digits. The checker state them as non-compliant. It's the same as for the initial comment: int c41_5 = '\0'; uses just less octal digits but should not generate a MISRA 4.1 violation. Hope this sounds plausible ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The following addition generates false positive in MISRA rule 4.1
I can reproduce it and this clearly should not be, so i created ticket https://trac.cppcheck.net/ticket/9370
But interestingly it seems to pass if I use 'python -m pytest addons/test/test-misra.py' instead of calling it directly.
The checker for MISRA rule 4.1 works fine for compliant and non-compliant examples part of MISRA 2012 document. However if the hexadecimal and octal escape sequences are not of full length (\x + 2 hex digits or \ + 3 octal digits) than the checker generates false positives. The following lines generate false positives but from my point of view they are compliant. The last one leads to an out of range exception and terminates the MISRA python addon.
Do you mean
instead of
?
Otherwise the multi-character character constant seems to have implementation defined behaviour and is not forbidden in C. So this could also be used as an example throwing some warning (maybe not 4.1).
I mean
MISRA rule 4.1 states
int c41_4 = '\141\t';as compliant and the above lines just use less than 3 octal digits. The checker state them as non-compliant. It's the same as for the initial comment:int c41_5 = '\0';uses just less octal digits but should not generate a MISRA 4.1 violation. Hope this sounds plausible ?Yes, i see. MISRA uses similar examples, so that makes sense.
Here is PR that will fix rule 4.1.
@mschmid @whoopsmith could you please check that version of misra.py with yours codebase?
Thank. I'll try to test it later on today.
See my note on the PR. It now throws errors for stuff like this:
static const char * mfg_pass = "pass";
The PR has been merged (Thanks @Georgy Komarov): https://github.com/danmar/cppcheck/commit/846f356db40ecd29f52c7ad119d6a75db37ddd13
Verification of MISRA rule 4.1 should work much better now.
If there are still issues, please report them.