Skip to content

Commit 7af46a5

Browse files
authored
Merge pull request #591 from github/mbaluda/importMisra23
Implement MISRA23 Import rules
2 parents 54492b0 + abf3f35 commit 7af46a5

File tree

50 files changed

+1631
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1631
-132
lines changed

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

+401
Large diffs are not rendered by default.

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

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Expressions
2121
import Freed
2222
import Functions
2323
import IO
24+
import ImportMisra23
2425
import Includes
2526
import Inheritance
2627
import Initialization
@@ -74,6 +75,7 @@ newtype TCPPQuery =
7475
TFreedPackageQuery(FreedQuery q) or
7576
TFunctionsPackageQuery(FunctionsQuery q) or
7677
TIOPackageQuery(IOQuery q) or
78+
TImportMisra23PackageQuery(ImportMisra23Query q) or
7779
TIncludesPackageQuery(IncludesQuery q) or
7880
TInheritancePackageQuery(InheritanceQuery q) or
7981
TInitializationPackageQuery(InitializationQuery q) or
@@ -127,6 +129,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
127129
isFreedQueryMetadata(query, queryId, ruleId, category) or
128130
isFunctionsQueryMetadata(query, queryId, ruleId, category) or
129131
isIOQueryMetadata(query, queryId, ruleId, category) or
132+
isImportMisra23QueryMetadata(query, queryId, ruleId, category) or
130133
isIncludesQueryMetadata(query, queryId, ruleId, category) or
131134
isInheritanceQueryMetadata(query, queryId, ruleId, category) or
132135
isInitializationQueryMetadata(query, queryId, ruleId, category) or
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id cpp/misra/sections-of-code-should-not-be-commented-out
3+
* @name DIR-5-7-2: Sections of code should not be “commented out”
4+
* @description Commented out code may become out of date leading to developer confusion.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/misra/id/dir-5-7-2
9+
* maintainability
10+
* readability
11+
* correctness
12+
* external/misra/obligation/advisory
13+
*/
14+
15+
import cpp
16+
import codingstandards.cpp.misra
17+
import codingstandards.cpp.rules.sectionsofcodeshallnotbecommentedout.SectionsOfCodeShallNotBeCommentedOut
18+
19+
class SectionsOfCodeShouldNotBeCommentedOutQuery extends SectionsOfCodeShallNotBeCommentedOutSharedQuery
20+
{
21+
SectionsOfCodeShouldNotBeCommentedOutQuery() {
22+
this = ImportMisra23Package::sectionsOfCodeShouldNotBeCommentedOutQuery()
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id cpp/misra/declaration-of-an-object-indirections-level
3+
* @name RULE-11-3-2: The declaration of an object should contain no more than two levels of pointer indirection
4+
* @description Declarations with more than two levels of pointer nesting can result in code that is
5+
* difficult to read and understand.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-11-3-2
10+
* readability
11+
* maintainability
12+
* scope/single-translation-unit
13+
* external/misra/enforcement/decidable
14+
* external/misra/obligation/advisory
15+
*/
16+
17+
import cpp
18+
import codingstandards.cpp.misra
19+
import codingstandards.cpp.rules.donotusemorethantwolevelsofpointerindirection.DoNotUseMoreThanTwoLevelsOfPointerIndirection
20+
21+
class DeclarationOfAnObjectIndirectionsLevelQuery extends DoNotUseMoreThanTwoLevelsOfPointerIndirectionSharedQuery
22+
{
23+
DeclarationOfAnObjectIndirectionsLevelQuery() {
24+
this = ImportMisra23Package::declarationOfAnObjectIndirectionsLevelQuery()
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @id cpp/misra/handlers-refer-to-non-static-members-from-their-class
3+
* @name RULE-18-3-3: Handlers for a function-try-block of a constructor or destructor shall not refer to non-static
4+
* @description Handlers for a function-try-block of a constructor or destructor shall not refer to
5+
* non-static members from their class or its bases.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-18-3-3
10+
* correctness
11+
* scope/single-translation-unit
12+
* external/misra/enforcement/decidable
13+
* external/misra/obligation/required
14+
*/
15+
16+
import cpp
17+
import codingstandards.cpp.misra
18+
import codingstandards.cpp.rules.destroyedvaluereferencedindestructorcatchblock.DestroyedValueReferencedInDestructorCatchBlock
19+
20+
class HandlersReferToNonStaticMembersFromTheirClassQuery extends DestroyedValueReferencedInDestructorCatchBlockSharedQuery
21+
{
22+
HandlersReferToNonStaticMembersFromTheirClassQuery() {
23+
this = ImportMisra23Package::handlersReferToNonStaticMembersFromTheirClassQuery()
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @id cpp/misra/include-directives-preceded-by-preprocessor-directives
3+
* @name RULE-19-0-3: #include directives should only be preceded by preprocessor directives or comments
4+
* @description Using anything other than other pre-processor directives or comments before an
5+
* '#include' directive makes the code more difficult to read.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-19-0-3
10+
* readability
11+
* scope/single-translation-unit
12+
* external/misra/enforcement/decidable
13+
* external/misra/obligation/advisory
14+
*/
15+
16+
import cpp
17+
import codingstandards.cpp.misra
18+
import codingstandards.cpp.rules.preprocessorincludespreceded.PreprocessorIncludesPreceded
19+
20+
class IncludeDirectivesPrecededByPreprocessorDirectivesQuery extends PreprocessorIncludesPrecededSharedQuery
21+
{
22+
IncludeDirectivesPrecededByPreprocessorDirectivesQuery() {
23+
this = ImportMisra23Package::includeDirectivesPrecededByPreprocessorDirectivesQuery()
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @id cpp/misra/identifiers-used-in-the-controlling-expression-of
3+
* @name RULE-19-1-3: All identifiers used in the controlling expression of #if or #elif preprocessing directives shall be
4+
* @description All identifiers used in the controlling expression of #if or #elif preprocessing
5+
* directives shall be defined prior to evaluation.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-19-1-3
10+
* correctness
11+
* readability
12+
* scope/single-translation-unit
13+
* external/misra/enforcement/decidable
14+
* external/misra/obligation/required
15+
*/
16+
17+
import cpp
18+
import codingstandards.cpp.misra
19+
import codingstandards.cpp.rules.undefinedmacroidentifiers.UndefinedMacroIdentifiers
20+
21+
class IdentifiersUsedInTheControllingExpressionOfQuery extends UndefinedMacroIdentifiersSharedQuery {
22+
IdentifiersUsedInTheControllingExpressionOfQuery() {
23+
this = ImportMisra23Package::identifiersUsedInTheControllingExpressionOfQuery()
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @id cpp/misra/chars-that-should-not-occur-in-header-file-name
3+
* @name RULE-19-2-3: The ' or " or \ characters and the /* or // character sequences shall not occur in a header file
4+
* @description The ' or " or \ characters and the /* or // character sequences shall not occur in a
5+
* header file name.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-19-2-3
10+
* scope/single-translation-unit
11+
* correctness
12+
* external/misra/enforcement/decidable
13+
* external/misra/obligation/required
14+
*/
15+
16+
import cpp
17+
import codingstandards.cpp.misra
18+
import codingstandards.cpp.rules.preprocessorincludesforbiddenheadernames.PreprocessorIncludesForbiddenHeaderNames
19+
20+
class CharsThatShouldNotOccurInHeaderFileNameQuery extends PreprocessorIncludesForbiddenHeaderNamesSharedQuery
21+
{
22+
CharsThatShouldNotOccurInHeaderFileNameQuery() {
23+
this = ImportMisra23Package::charsThatShouldNotOccurInHeaderFileNameQuery()
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id cpp/misra/and-preprocessor-operators-should-not-be-used
3+
* @name RULE-19-3-1: The # and ## preprocessor operators should not be used
4+
* @description The order of evaluation for the '#' and '##' operators may differ between compilers,
5+
* which can cause unexpected behaviour.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-19-3-1
10+
* correctness
11+
* scope/single-translation-unit
12+
* external/misra/enforcement/decidable
13+
* external/misra/obligation/advisory
14+
*/
15+
16+
import cpp
17+
import codingstandards.cpp.misra
18+
import codingstandards.cpp.rules.hashoperatorsused.HashOperatorsUsed
19+
20+
class AndPreprocessorOperatorsShouldNotBeUsedQuery extends HashOperatorsUsedSharedQuery {
21+
AndPreprocessorOperatorsShouldNotBeUsedQuery() {
22+
this = ImportMisra23Package::andPreprocessorOperatorsShouldNotBeUsedQuery()
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id cpp/misra/tokens-that-look-like-directives-in-a-macro-argument
3+
* @name RULE-19-3-5: Tokens that look like a preprocessing directive shall not occur within a macro argument
4+
* @description Arguments to a function-like macro shall not contain tokens that look like
5+
* pre-processing directives or else behaviour after macro expansion is unpredictable.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-19-3-5
10+
* readability
11+
* correctness
12+
* scope/single-translation-unit
13+
* external/misra/enforcement/decidable
14+
* external/misra/obligation/required
15+
*/
16+
17+
import cpp
18+
import codingstandards.cpp.misra
19+
import codingstandards.cpp.rules.preprocessingdirectivewithinmacroargument.PreprocessingDirectiveWithinMacroArgument
20+
21+
class TokensThatLookLikeDirectivesInAMacroArgumentQuery extends PreprocessingDirectiveWithinMacroArgumentSharedQuery
22+
{
23+
TokensThatLookLikeDirectivesInAMacroArgumentQuery() {
24+
this = ImportMisra23Package::tokensThatLookLikeDirectivesInAMacroArgumentQuery()
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id cpp/misra/pointer-to-an-incomplete-class-type-deleted
3+
* @name RULE-21-6-5: A pointer to an incomplete class type shall not be deleted
4+
* @description Do not delete pointers to incomplete classes to prevent undefined behavior.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/misra/id/rule-21-6-5
9+
* correctness
10+
* scope/single-translation-unit
11+
* external/misra/enforcement/decidable
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.cpp.misra
17+
import codingstandards.cpp.rules.deleteofpointertoincompleteclass.DeleteOfPointerToIncompleteClass
18+
19+
class PointerToAnIncompleteClassTypeDeletedQuery extends DeleteOfPointerToIncompleteClassSharedQuery
20+
{
21+
PointerToAnIncompleteClassTypeDeletedQuery() {
22+
this = ImportMisra23Package::pointerToAnIncompleteClassTypeDeletedQuery()
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id cpp/misra/pointers-returned-by-locale-functions-must-be-used-as-const
3+
* @name RULE-25-5-2: The pointers returned by environment functions should be treated as const
4+
* @description The pointers returned by the C++ Standard Library functions localeconv, getenv,
5+
* setlocale or strerror must only be used as if they have pointer to const-qualified
6+
* type.
7+
* @kind path-problem
8+
* @precision very-high
9+
* @problem.severity error
10+
* @tags external/misra/id/rule-25-5-2
11+
* correctness
12+
* scope/single-translation-unit
13+
* external/misra/enforcement/decidable
14+
* external/misra/obligation/mandatory
15+
*/
16+
17+
import cpp
18+
import codingstandards.cpp.misra
19+
import codingstandards.cpp.rules.constlikereturnvalue.ConstLikeReturnValue
20+
21+
class PointersReturnedByLocaleFunctionsMustBeUsedAsConstQuery extends ConstLikeReturnValueSharedQuery
22+
{
23+
PointersReturnedByLocaleFunctionsMustBeUsedAsConstQuery() {
24+
this = ImportMisra23Package::pointersReturnedByLocaleFunctionsMustBeUsedAsConstQuery()
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id cpp/misra/call-to-setlocale-invalidates-old-pointers-misra
3+
* @name RULE-25-5-3: The pointer returned by the Standard Library env functions is invalid
4+
* @description The pointer returned by the Standard Library functions asctime, ctime, gmtime,
5+
* localtime, localeconv, getenv, setlocale or strerror may be invalid following a
6+
* subsequent call to the same function.
7+
* @kind problem
8+
* @precision very-high
9+
* @problem.severity error
10+
* @tags external/misra/id/rule-25-5-3
11+
* correctness
12+
* scope/system
13+
* external/misra/enforcement/undecidable
14+
* external/misra/obligation/mandatory
15+
*/
16+
17+
import cpp
18+
import codingstandards.cpp.misra
19+
import codingstandards.cpp.rules.invalidatedenvstringpointers.InvalidatedEnvStringPointers
20+
21+
class CallToSetlocaleInvalidatesOldPointersMisraQuery extends InvalidatedEnvStringPointersSharedQuery
22+
{
23+
CallToSetlocaleInvalidatesOldPointersMisraQuery() {
24+
this = ImportMisra23Package::callToSetlocaleInvalidatesOldPointersMisraQuery()
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id cpp/misra/call-to-setlocale-invalidates-old-pointers-warn-misra
3+
* @name RULE-25-5-3: The pointer returned by the Standard Library env functions is invalid warning
4+
* @description The pointer returned by the Standard Library functions asctime, ctime, gmtime,
5+
* localtime, localeconv, getenv, setlocale or strerror may be invalid following a
6+
* subsequent call to the same function.
7+
* @kind problem
8+
* @precision very-high
9+
* @problem.severity warning
10+
* @tags external/misra/id/rule-25-5-3
11+
* correctness
12+
* scope/system
13+
* external/misra/enforcement/undecidable
14+
* external/misra/obligation/mandatory
15+
*/
16+
17+
import cpp
18+
import codingstandards.cpp.misra
19+
import codingstandards.cpp.rules.invalidatedenvstringpointerswarn.InvalidatedEnvStringPointersWarn
20+
21+
class CallToSetlocaleInvalidatesOldPointersWarnMisraQuery extends InvalidatedEnvStringPointersWarnSharedQuery
22+
{
23+
CallToSetlocaleInvalidatesOldPointersWarnMisraQuery() {
24+
this = ImportMisra23Package::callToSetlocaleInvalidatesOldPointersWarnMisraQuery()
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @id cpp/misra/object-used-while-in-potentially-moved-from-state
3+
* @name RULE-28-6-3: An object shall not be used while in a potentially moved-from state
4+
* @description Moved-from object shall not be read-accessed.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/misra/id/rule-28-6-3
9+
* correctness
10+
* scope/single-translation-unit
11+
* external/misra/enforcement/decidable
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.cpp.misra
17+
import codingstandards.cpp.rules.movedfromobjectsunspecifiedstate.MovedFromObjectsUnspecifiedState
18+
19+
class ObjectUsedWhileInPotentiallyMovedFromStateQuery extends MovedFromObjectsUnspecifiedStateSharedQuery
20+
{
21+
ObjectUsedWhileInPotentiallyMovedFromStateQuery() {
22+
this = ImportMisra23Package::objectUsedWhileInPotentiallyMovedFromStateQuery()
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @id cpp/misra/reads-and-writes-on-stream-not-separated-by-positioning
3+
* @name RULE-30-0-2: Reads and writes on the same file stream shall be separated by a positioning operation
4+
* @description Alternate input and output operations on a file stream shall not be used without an
5+
* intervening flush or positioning call.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-30-0-2
10+
* correctness
11+
* scope/system
12+
* external/misra/enforcement/undecidable
13+
* external/misra/obligation/required
14+
*/
15+
16+
import cpp
17+
import codingstandards.cpp.misra
18+
import codingstandards.cpp.rules.iofstreammissingpositioning.IOFstreamMissingPositioning
19+
20+
class ReadsAndWritesOnStreamNotSeparatedByPositioningQuery extends IOFstreamMissingPositioningSharedQuery
21+
{
22+
ReadsAndWritesOnStreamNotSeparatedByPositioningQuery() {
23+
this = ImportMisra23Package::readsAndWritesOnStreamNotSeparatedByPositioningQuery()
24+
}
25+
}

0 commit comments

Comments
 (0)