-
Notifications
You must be signed in to change notification settings - Fork 1.5k
misra.py: Fix Rule 4.1 #2216
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
misra.py: Fix Rule 4.1 #2216
Conversation
|
@matzeschmid @whoopsmith could you please review these changes before merging? This solves the problems on your codebase? |
|
If you add a max. sequence length check in |
|
I removed the restriction to just check assignments to see how the fix works for non-assignment test cases. After that it generates false positives because the escape sequence split adds a '\' to each sub-token. Thus the line Sequence split line in script. |
addons/misra.py
Outdated
| def isHexEscapeSequence(symbols): | ||
| """Checks that given symbols are valid hex escape sequence. | ||
| Reference: n1570 6.4.4.4""" | ||
| if len(symbols) < 3 or symbols[0] != '\\' or symbols[1] != 'x': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could compress this condition I think:
if len(symbols) < 3 or symbols[:2] != '\\x':
|
Doesn't work for me at all. It throws 4.1 errors all over the place for things that are not octal sequences. Like below: static const char * mfg_pass = "pass"; |
|
Thanks for the thorough review. |
I think the wrong sequence split described above generates most of the false positives. |
|
I ran the latest revision and all the false positives are gone. I haven't tested if a valid error gets caught yet. |
* misra.py: Use standard string module * misra.py: Fixup R4.1 References: * https://trac.cppcheck.net/ticket/9370 * https://sourceforge.net/p/cppcheck/discussion/development/thread/7274ed3842/?limit=25#799a * Add more examples from @matzeschmid PR * Add more out-of-bounds tests * Fix R4.1. * Compress hex condition * Add more test cases * Fix python3 zip import
This commit will fix issues with MISRA rule 4.1 caused by improper escape sequences handling.
References: