-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change treatment plain char type and CV qualified integer types.
The plain char type can hold numeric data, but is frequently used to hold character data. To be able to support the case where a plain char type holds character data we split the rule into two queries. One considering all the variable width integer types excluding the plain char type and one considering just the plain char type. This allows for deviation on the second case. Additionally, the original query wasn't considering CV qualified variable with integer types. Those are now included.
- Loading branch information
1 parent
d9f0911
commit cb41055
Showing
10 changed files
with
151 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- `A3-9-1` - `VariableWidthIntegerTypesUsed.ql`: | ||
- Exclude the plain char type. Still includes `signed char` and `unsigned char`. | ||
- Include CV-qualified variable width integer types. | ||
- `A3-9-1` - `VariableWidthPlainCharTypeUsed.ql`: | ||
- New query to support fine grained deviation support for the plain char type. |
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
26 changes: 26 additions & 0 deletions
26
cpp/autosar/src/rules/A3-9-1/VariableWidthPlainCharTypeUsed.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,26 @@ | ||
/** | ||
* @id cpp/autosar/variable-width-plain-char-types-used | ||
* @name A3-9-1: Use a fixed-width integer type instead of a char type | ||
* @description The basic numerical type char is not supposed to be used. The specific-length types | ||
* from <cstdint> header need be used instead. | ||
* @kind problem | ||
* @precision very-high | ||
* @problem.severity error | ||
* @tags external/autosar/id/a3-9-1 | ||
* correctness | ||
* security | ||
* maintainability | ||
* external/autosar/allocated-target/implementation | ||
* external/autosar/enforcement/automated | ||
* external/autosar/obligation/required | ||
*/ | ||
|
||
import cpp | ||
import codingstandards.cpp.autosar | ||
import codingstandards.cpp.Type | ||
|
||
from Variable variable | ||
where | ||
not isExcluded(variable, DeclarationsPackage::variableWidthPlainCharTypeUsedQuery()) and | ||
stripSpecifiers(variable.getType()) instanceof PlainCharType | ||
select variable, "Variable '" + variable.getName() + "' has variable-width char type." |
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
3 changes: 3 additions & 0 deletions
3
cpp/autosar/test/rules/A3-9-1/VariableWidthPlainCharTypeUsed.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,3 @@ | ||
| test.cpp:4:8:4:8 | c | Variable 'c' has variable-width char type. | | ||
| test.cpp:38:14:38:15 | c1 | Variable 'c1' has variable-width char type. | | ||
| test.cpp:56:17:56:18 | c2 | Variable 'c2' has variable-width char type. | |
1 change: 1 addition & 0 deletions
1
cpp/autosar/test/rules/A3-9-1/VariableWidthPlainCharTypeUsed.qlref
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 @@ | ||
rules/A3-9-1/VariableWidthPlainCharTypeUsed.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
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
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