Skip to content

Commit 5b37d13

Browse files
committed
Rule 6.9.2: AvoidStandardIntegerTypeNames.ql
Adds a new query for detecting the use of the standard integer types.
1 parent 54fe5ea commit 5b37d13

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

cpp/common/src/codingstandards/cpp/exclusions/cpp/BannedAPIs.qll

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ newtype BannedAPIsQuery =
1212
TUseSmartPtrFactoryFunctionsQuery() or
1313
TCharacterHandlingFunctionRestrictionsQuery() or
1414
TNoMemoryFunctionsFromCStringQuery() or
15-
TLocaleGlobalFunctionNotAllowedQuery()
15+
TLocaleGlobalFunctionNotAllowedQuery() or
16+
TAvoidStandardIntegerTypeNamesQuery()
1617

1718
predicate isBannedAPIsQueryMetadata(Query query, string queryId, string ruleId, string category) {
1819
query =
@@ -95,6 +96,15 @@ predicate isBannedAPIsQueryMetadata(Query query, string queryId, string ruleId,
9596
"cpp/misra/locale-global-function-not-allowed" and
9697
ruleId = "RULE-25-5-1" and
9798
category = "required"
99+
or
100+
query =
101+
// `Query` instance for the `avoidStandardIntegerTypeNames` query
102+
BannedAPIsPackage::avoidStandardIntegerTypeNamesQuery() and
103+
queryId =
104+
// `@id` for the `avoidStandardIntegerTypeNames` query
105+
"cpp/misra/avoid-standard-integer-type-names" and
106+
ruleId = "RULE-6-9-2" and
107+
category = "advisory"
98108
}
99109

100110
module BannedAPIsPackage {
@@ -160,4 +170,11 @@ module BannedAPIsPackage {
160170
// `Query` type for `localeGlobalFunctionNotAllowed` query
161171
TQueryCPP(TBannedAPIsPackageQuery(TLocaleGlobalFunctionNotAllowedQuery()))
162172
}
173+
174+
Query avoidStandardIntegerTypeNamesQuery() {
175+
//autogenerate `Query` type
176+
result =
177+
// `Query` type for `avoidStandardIntegerTypeNames` query
178+
TQueryCPP(TBannedAPIsPackageQuery(TAvoidStandardIntegerTypeNamesQuery()))
179+
}
163180
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @id cpp/misra/avoid-standard-integer-type-names
3+
* @name RULE-6-9-2: The names of the standard signed integer types and standard unsigned integer types should not be
4+
* @description Using standard signed and unsigned integer type names instead of specified width
5+
* types makes storage requirements unclear and implementation-dependent.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-6-9-2
10+
* scope/single-translation-unit
11+
* external/misra/enforcement/decidable
12+
* external/misra/obligation/advisory
13+
*/
14+
15+
import cpp
16+
import codingstandards.cpp.misra
17+
import codingstandards.cpp.rules.variablewidthintegertypesused.VariableWidthIntegerTypesUsed
18+
19+
class AvoidStandardIntegerTypeNamesQuery extends VariableWidthIntegerTypesUsedSharedQuery {
20+
AvoidStandardIntegerTypeNamesQuery() {
21+
this = BannedAPIsPackage::avoidStandardIntegerTypeNamesQuery()
22+
}
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/variablewidthintegertypesused/VariableWidthIntegerTypesUsed.ql

rule_packages/cpp/BannedAPIs.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,27 @@
179179
}
180180
],
181181
"title": "The setlocale and std::locale::global functions shall not be called"
182+
},
183+
"RULE-6-9-2": {
184+
"properties": {
185+
"enforcement": "decidable",
186+
"obligation": "advisory"
187+
},
188+
"queries": [
189+
{
190+
"description": "Using standard signed and unsigned integer type names instead of specified width types makes storage requirements unclear and implementation-dependent.",
191+
"kind": "problem",
192+
"name": "The names of the standard signed integer types and standard unsigned integer types should not be",
193+
"precision": "very-high",
194+
"severity": "error",
195+
"short_name": "AvoidStandardIntegerTypeNames",
196+
"shared_implementation_short_name": "VariableWidthIntegerTypesUsed",
197+
"tags": [
198+
"scope/single-translation-unit"
199+
]
200+
}
201+
],
202+
"title": "The names of the standard signed integer types and standard unsigned integer types should not be used"
182203
}
183204
}
184205
}

rules.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ cpp,MISRA-C++-2023,RULE-6-8-2,Yes,Mandatory,Decidable,Single Translation Unit,A
869869
cpp,MISRA-C++-2023,RULE-6-8-3,Yes,Required,Decidable,Single Translation Unit,An assignment operator shall not assign the address of an object with automatic storage duration to an object with a greater lifetime,,Lifetime,Medium,
870870
cpp,MISRA-C++-2023,RULE-6-8-4,Yes,Advisory,Decidable,Single Translation Unit,Member functions returning references to their object should be refqualified appropriately,,Declarations2,Medium,
871871
cpp,MISRA-C++-2023,RULE-6-9-1,Yes,Required,Decidable,Single Translation Unit,The same type aliases shall be used in all declarations of the same entity,,Declarations2,Medium,
872-
cpp,MISRA-C++-2023,RULE-6-9-2,Yes,Advisory,Decidable,Single Translation Unit,The names of the standard signed integer types and standard unsigned integer types should not be used,A3-9-1,FixedWithInt,Easy,
872+
cpp,MISRA-C++-2023,RULE-6-9-2,Yes,Advisory,Decidable,Single Translation Unit,The names of the standard signed integer types and standard unsigned integer types should not be used,A3-9-1,BannedAPIs,Easy,
873873
cpp,MISRA-C++-2023,RULE-7-0-1,Yes,Required,Decidable,Single Translation Unit,There shall be no conversion from type bool,,Conversions,Easy,
874874
cpp,MISRA-C++-2023,RULE-7-0-2,Yes,Required,Decidable,Single Translation Unit,There shall be no conversion to type bool,,Conversions,Easy,
875875
cpp,MISRA-C++-2023,RULE-7-0-3,Yes,Required,Decidable,Single Translation Unit,The numerical value of a character shall not be used,M5-0-11,Conversions,Medium,

0 commit comments

Comments
 (0)