-
Notifications
You must be signed in to change notification settings - Fork 59
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
STR34-C: Do not consider integer type aliases in templates #635
Open
mbaluda
wants to merge
6
commits into
main
Choose a base branch
from
mabluda/fix576
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
87fa7c1
STR34-C: Do not consider integer type aliases in templates
mbaluda dc6bed1
Add change notes
mbaluda e3a5b8c
renamed the shared query
mbaluda 946d5df
Fix formatting
mbaluda f154426
Merge branch 'main' into mabluda/fix576
mbaluda ed381ef
Merge branch 'main' into mabluda/fix576
mbaluda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
c/cert/test/rules/STR34-C/CastCharBeforeConvertingToLargerSizes.expected
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
c/cert/test/rules/STR34-C/CastCharBeforeConvertingToLargerSizes.qlref
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
c/cert/test/rules/STR34-C/CastCharBeforeConvertingToLargerSizes.testref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
c/common/test/rules/castcharbeforeconvertingtolargersizes/CastCharBeforeConvertingToLargerSizes.ql |
21 changes: 21 additions & 0 deletions
21
...ules/castcharbeforeconvertingtolargersizes/CastCharBeforeConvertingToLargerSizes.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
| test.c:9:7:9:14 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:30:11:30:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:31:3:31:13 | (unsigned int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:31:11:31:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:33:11:33:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:34:11:34:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:35:3:35:13 | (unsigned int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:35:11:35:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:36:3:36:13 | (unsigned int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:36:11:36:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:37:3:37:13 | (unsigned int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:37:11:37:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:38:3:38:13 | (unsigned int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:38:11:38:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:39:11:39:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:40:11:40:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:41:3:41:13 | (unsigned int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:41:11:41:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:42:12:42:13 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:44:11:44:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:45:11:45:12 | (int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | |
14 changes: 7 additions & 7 deletions
14
...oreConvertingToLargerSizes.expected.clang → ...oreConvertingToLargerSizes.expected.clang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
| test.c:7:7:7:14 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:28:3:28:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:29:3:29:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:9:7:9:14 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:30:3:30:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:31:3:31:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:32:3:32:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:33:3:33:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:34:3:34:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:35:3:35:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:36:3:36:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:37:3:37:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:38:3:38:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:39:3:39:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:40:3:40:14 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:42:11:42:12 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:43:11:43:12 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:40:3:40:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:41:3:41:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:42:3:42:14 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:44:11:44:12 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:45:11:45:12 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | |
12 changes: 6 additions & 6 deletions
12
...eforeConvertingToLargerSizes.expected.gcc → ...eforeConvertingToLargerSizes.expected.gcc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
| test.c:7:7:7:14 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:28:3:28:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:29:3:29:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:9:7:9:14 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:30:3:30:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:31:3:31:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:32:3:32:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:33:3:33:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:34:3:34:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:35:3:35:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:36:3:36:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:37:3:37:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:38:3:38:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:39:3:39:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:40:3:40:14 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:42:11:42:12 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:40:3:40:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:41:3:41:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:42:3:42:14 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:43:11:43:12 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:44:11:44:12 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | |
14 changes: 7 additions & 7 deletions
14
...eforeConvertingToLargerSizes.expected.qcc → ...eforeConvertingToLargerSizes.expected.qcc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
| test.c:7:7:7:14 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:28:3:28:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:29:3:29:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:9:7:9:14 | * ... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:30:3:30:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:31:3:31:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:32:3:32:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:33:3:33:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:34:3:34:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:35:3:35:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:36:3:36:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:37:3:37:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:38:3:38:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:39:3:39:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:40:3:40:14 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:42:3:42:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:43:3:43:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:40:3:40:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:41:3:41:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:42:3:42:14 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:44:3:44:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.c:45:3:45:13 | (...) | Expression not converted to `unsigned char` before converting to a larger integer type. | |
4 changes: 4 additions & 0 deletions
4
...test/rules/castcharbeforeconvertingtolargersizes/CastCharBeforeConvertingToLargerSizes.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// GENERATED FILE - DO NOT MODIFY | ||
import codingstandards.cpp.rules.castcharbeforeconvertingtolargersizes.CastCharBeforeConvertingToLargerSizes | ||
|
||
class TestFileQuery extends CastCharBeforeConvertingToLargerSizesSharedQuery, TestQuery { } |
2 changes: 2 additions & 0 deletions
2
c/cert/test/rules/STR34-C/test.c → ...tcharbeforeconvertingtolargersizes/test.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- `STR34-C` - `CastCharBeforeConvertingToLargerSizes.ql`: | ||
- Fixes #576. Do not consider integer type aliases in templates. |
26 changes: 26 additions & 0 deletions
26
...cpp/rules/castcharbeforeconvertingtolargersizes/CastCharBeforeConvertingToLargerSizes.qll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Provides a library which includes a `problems` predicate for reporting.... | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.cpp.Customizations | ||
import codingstandards.cpp.Exclusions | ||
|
||
abstract class CastCharBeforeConvertingToLargerSizesSharedQuery extends Query { } | ||
|
||
Query getQuery() { result instanceof CastCharBeforeConvertingToLargerSizesSharedQuery } | ||
|
||
query predicate problems(Cast c, string message) { | ||
not isExcluded(c, getQuery()) and | ||
// find cases where there is a conversion happening wherein the | ||
// base type is a char | ||
c.getExpr().getType() instanceof CharType and | ||
not c.getExpr().getType() instanceof UnsignedCharType and | ||
// it's a bigger type | ||
c.getType().getSize() > c.getExpr().getType().getSize() and | ||
// and it's some kind of integer type | ||
c.getType().getUnderlyingType() instanceof IntegralType and | ||
not c.isFromTemplateInstantiation(_) and | ||
message = | ||
"Expression not converted to `unsigned char` before converting to a larger integer type." | ||
} |
2 changes: 2 additions & 0 deletions
2
...ules/castcharbeforeconvertingtolargersizes/CastCharBeforeConvertingToLargerSizes.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
| test.cpp:11:9:11:9 | (int32_t)... | Expression not converted to `unsigned char` before converting to a larger integer type. | | ||
| test.cpp:12:41:12:41 | (signed int)... | Expression not converted to `unsigned char` before converting to a larger integer type. | |
4 changes: 4 additions & 0 deletions
4
...test/rules/castcharbeforeconvertingtolargersizes/CastCharBeforeConvertingToLargerSizes.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// GENERATED FILE - DO NOT MODIFY | ||
import codingstandards.cpp.rules.castcharbeforeconvertingtolargersizes.CastCharBeforeConvertingToLargerSizes | ||
|
||
class TestFileQuery extends CastCharBeforeConvertingToLargerSizesSharedQuery, TestQuery { } |
17 changes: 17 additions & 0 deletions
17
cpp/common/test/rules/castcharbeforeconvertingtolargersizes/test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C TEST CASE AND | ||
// CHANGES SHOULD BE REFLECTED THERE AS WELL. | ||
#include <cstdint> | ||
|
||
template <typename S, typename T> S get(T t) { | ||
S s = t; // COMPLIANT | ||
return s; | ||
} | ||
|
||
void test(std::int32_t i32, std::int8_t i8, char c) { | ||
i32 = c; // NON_COMPLIANT | ||
i32 = get<std::int32_t, std::int32_t>(c); // NON_COMPLIANT | ||
i32 = get<std::int32_t, std::int8_t>(c); // COMPLIANT | ||
i32 = i8; // COMPLIANT | ||
i32 = get<std::int32_t, std::int32_t>(i8); // COMPLIANT | ||
i32 = get<std::int32_t, std::int8_t>(i8); // COMPLIANT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
when the rule is shared between c and c++, doesnt it need to have the shared implementation name portion in the package description file for both c/c++?
for example like this?
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.
There is no c++ rule using this query.
It's just that the issue is related to using the query on c++ code, so I needed a c++ test.
That's why I had to move things around