-
Notifications
You must be signed in to change notification settings - Fork 68
Fix False Positives of M5-0-12
#925
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
Conversation
- 1. Assigning a char to another char - 1-1. Assigning a char to a char variable - 1-2. Assigning a char to a char member - 1-3. Assigning a char to a char through a pointer - 2. Passing a char argument to a char parameter - 2-1. Passing char argument to a char parameter of a regular function - 2-2. Passing char argument to a char parameter through a template - 2-3. Passing a char argument to a char parameter through a template
…oding-standards into jeongsoolee09/FP-M5-0-12
This query runs on openpilot-72d1744 in 17 seconds (on an M1 Max MacBook), and produces one true positive result. |
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.
Pull Request Overview
This PR fixes false positives in rule M5-0-12 by improving the detection of implicit conversions from plain char to explicitly signed/unsigned char types. The fix addresses scenarios involving templates and provides more accurate reporting of where violations occur.
Key Changes:
- Complete rewrite of the query logic to handle template instantiations properly
- Enhanced test coverage with comprehensive template scenarios
- Updated expected results to reflect accurate violation detection
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql |
Complete rewrite with new classes to handle template instantiations and implicit conversions |
test.cpp |
Extensive expansion of test cases covering templates, function calls, and various char type scenarios |
SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.expected |
Updated expected results reflecting the improved detection logic |
Comments suppressed due to low confidence (2)
cpp/autosar/test/rules/M5-0-12/test.cpp:92
- [nitpick] The variable names 'v1' and 'v2' are not descriptive. Consider using more meaningful names like 'templateVarUnsigned' and 'templateVarSigned'.
v1<unsigned char> =
...es/M5-0-12/SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql
Outdated
Show resolved
Hide resolved
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.
Nice!!
...es/M5-0-12/SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql
Outdated
Show resolved
Hide resolved
...es/M5-0-12/SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql
Outdated
Show resolved
Hide resolved
...es/M5-0-12/SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql
Outdated
Show resolved
Hide resolved
...es/M5-0-12/SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql
Outdated
Show resolved
Hide resolved
...es/M5-0-12/SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql
Outdated
Show resolved
Hide resolved
...es/M5-0-12/SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql
Outdated
Show resolved
Hide resolved
...es/M5-0-12/SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql
Outdated
Show resolved
Hide resolved
...es/M5-0-12/SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql
Outdated
Show resolved
Hide resolved
...es/M5-0-12/SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql
Outdated
Show resolved
Hide resolved
Templates are tricky issue; we'd like to address this in a different PR.
I have reduced the scope of this query to only deal with cases that does not involve templates, as templates are difficult topic and deserves a discussion of its own. Subsequently, both the test cases and the results are trimmed down. |
Looks great! If you're so inclined, it could be a good idea to add tests for const types and typedefs: typedef char char_t;
typedef unsigned char uchar_t;
const char x1 = 'a'; // compliant
const signed char x2 = x1; // non-compliant
char_t x3 = x1; // compliant
uchar_t x4 = x3; // non-compliant
// etc It looks like the code already handles these cases correctly, since it uses |
Description
Fix false positives of
M5-0-12
(Closes #541).Change request type
.ql
,.qll
,.qls
or unit tests)Rules with added or modified queries
Release change checklist
A change note (development_handbook.md#change-notes) is required for any pull request which modifies:
If you are only adding new rule queries, a change note is not required.
Author: Is a change note required?
🚨🚨🚨
Reviewer: Confirm that format of shared queries (not the .qll file, the
.ql file that imports it) is valid by running them within VS Code.
Reviewer: Confirm that either a change note is not required or the change note is required and has been added.
Query development review checklist
For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:
Author
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
Reviewer
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.