From 9a2090ab80999d137acae4b5522091cc1dc49177 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Thu, 3 Nov 2022 11:04:23 -0400 Subject: [PATCH 01/16] fix rule --- rules.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules.csv b/rules.csv index ec8b29eaf9..17560ac168 100644 --- a/rules.csv +++ b/rules.csv @@ -600,7 +600,7 @@ c,CERT-C,STR37-C,Yes,Rule,,,Arguments to character-handling functions must be re c,CERT-C,STR38-C,Yes,Rule,,,Do not confuse narrow and wide character strings and functions,,Strings3,Medium, c,CERT-C,WIN30-C,OutOfScope,Rule,,,Properly pair allocation and deallocation functions,DCL54-CPP,,Easy, c,MISRA-C-2012,RULE-1-1,No,Required,,,Any implementation-defined behaviour on which the output of the program depends shall be documented and understood,,,, -c,MISRA-C-2012,RULE-2-1,Yes,Required,,,All source files shall compile without any compilation errors,A1-4-3,Language,Medium, +c,MISRA-C-2012,DIR-2-1,Yes,Required,,,All source files shall compile without any compilation errors,A1-4-3,Language,Medium, c,MISRA-C-2012,RULE-3-1,No,Required,,,All code shall be traceable to documented requirements,,,, c,MISRA-C-2012,RULE-4-1,No,Required,,,Run-time failures shall be minimized,,,, c,MISRA-C-2012,RULE-4-2,Yes,Advisory,,,All usage of assembly language should be documented,M7-4-1,Language,Import, From 55b5fad5f55e64e322ab67b509f093a34fe3fa34 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Thu, 3 Nov 2022 11:56:14 -0400 Subject: [PATCH 02/16] scripts to check rules --- .../PSCodingStandards/Get-RulesFromCSV.ps1 | 29 ++++++++++++ scripts/util/Get-DuplicateRules.ps1 | 46 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 scripts/PSCodingStandards/Get-RulesFromCSV.ps1 create mode 100644 scripts/util/Get-DuplicateRules.ps1 diff --git a/scripts/PSCodingStandards/Get-RulesFromCSV.ps1 b/scripts/PSCodingStandards/Get-RulesFromCSV.ps1 new file mode 100644 index 0000000000..54c29668e4 --- /dev/null +++ b/scripts/PSCodingStandards/Get-RulesFromCSV.ps1 @@ -0,0 +1,29 @@ +function Get-RulesFromCSV { + param( + [ValidateSet('c', 'cpp', 'all')] + [string] + $Language = 'all') + + + $csvFile = (Join-Path (Get-RepositoryRoot) "rules.csv") + + Write-Host "Loading rules for language=$Language from file $csvFile..." + + $csv = Import-Csv $csvFile + $filteredCSV = @() + # don't filter if not neeeded + if ($Language -eq 'all'){ + $filteredCSV = $csv + }else{ + foreach($rule in $csv){ + if($rule.Language -eq $Language){ + $filteredCSV += $rule + } + } + } + + Write-Host "Loaded $($filteredCSV.Length) rules." + + return $csv + +} \ No newline at end of file diff --git a/scripts/util/Get-DuplicateRules.ps1 b/scripts/util/Get-DuplicateRules.ps1 new file mode 100644 index 0000000000..34ff565587 --- /dev/null +++ b/scripts/util/Get-DuplicateRules.ps1 @@ -0,0 +1,46 @@ +#!/usr/bin/env pwsh +param( + [ValidateSet('c', 'cpp', 'all')] + [string] + $Language = 'all', + [switch] + $CIMode + +) + +Import-Module -Name "$PSScriptRoot\..\PSCodingStandards\CodingStandards" + +# load the rules. +$rules = Get-RulesFromCSV -Language $Language + +# find out duplicates +$counter = @{} + +foreach($rule in $rules){ + if($counter.Contains($rule.ID)){ + $counter[$rule.ID] += $rule + }else{ + $counter[$rule.ID] = @() + $counter[$rule.ID] += $rule + } +} + +$duplicates = @() +$numDuplicates = 0 + +foreach($k in $counter.Keys){ + if($counter[$k].Count -gt 1){ + $numDuplicates = $numDuplicates + 1 + foreach($v in $counter[$k]){ + $duplicates += $v + } + } +} + +$duplicates | Format-Table + +if(($CIMode) -and ($numDuplicates -gt 0)){ + throw "Found $numDuplicates duplicate Rule IDs" +}else{ + Write-Host "Found $numDuplicates duplicate Rule IDs" +} \ No newline at end of file From de1d2167b77ef19257437a13732c16f2b5a763b3 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Thu, 3 Nov 2022 13:48:18 -0400 Subject: [PATCH 03/16] validate rules --- .github/workflows/validate-rules-csv.yml | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/validate-rules-csv.yml diff --git a/.github/workflows/validate-rules-csv.yml b/.github/workflows/validate-rules-csv.yml new file mode 100644 index 0000000000..df4ec09e6b --- /dev/null +++ b/.github/workflows/validate-rules-csv.yml @@ -0,0 +1,28 @@ +name: ⚙️ Validate Rules CSV + +on: + push: + branches: + - main + - "rc/**" + - next + pull_request: + branches: + - main + - "rc/**" + - next + + +jobs: + validate-rules-csv: + name: Validate Rules CSV + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Check Rules + shell: pwsh + run: scripts/util/Get-DuplicateRules.ps1 -Language 'all' -CIMode + + \ No newline at end of file From 5dbfb5245ee15a53e7eb01659b0b20d9cfe58cbd Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Thu, 3 Nov 2022 13:55:42 -0400 Subject: [PATCH 04/16] make better keys --- scripts/util/Get-DuplicateRules.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/util/Get-DuplicateRules.ps1 b/scripts/util/Get-DuplicateRules.ps1 index 34ff565587..5090f4628c 100644 --- a/scripts/util/Get-DuplicateRules.ps1 +++ b/scripts/util/Get-DuplicateRules.ps1 @@ -17,11 +17,12 @@ $rules = Get-RulesFromCSV -Language $Language $counter = @{} foreach($rule in $rules){ - if($counter.Contains($rule.ID)){ - $counter[$rule.ID] += $rule + $key = "$($rule.Language):$($rule.Standard):$($rule.ID)" + if($counter.Contains($key)){ + $counter[$key] += $rule }else{ - $counter[$rule.ID] = @() - $counter[$rule.ID] += $rule + $counter[$key] = @() + $counter[$key] += $rule } } From f3ec77fa83aa5afb7a67fea3ea58c6f08dc72ce4 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Thu, 3 Nov 2022 14:01:13 -0400 Subject: [PATCH 05/16] fixes to rules --- rules.csv | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/rules.csv b/rules.csv index 17560ac168..b10e97a9ba 100644 --- a/rules.csv +++ b/rules.csv @@ -599,23 +599,23 @@ c,CERT-C,STR34-C,Yes,Rule,,,Cast characters to unsigned char before converting t c,CERT-C,STR37-C,Yes,Rule,,,Arguments to character-handling functions must be representable as an unsigned char,,Strings2,Medium, c,CERT-C,STR38-C,Yes,Rule,,,Do not confuse narrow and wide character strings and functions,,Strings3,Medium, c,CERT-C,WIN30-C,OutOfScope,Rule,,,Properly pair allocation and deallocation functions,DCL54-CPP,,Easy, -c,MISRA-C-2012,RULE-1-1,No,Required,,,Any implementation-defined behaviour on which the output of the program depends shall be documented and understood,,,, +c,MISRA-C-2012,DIR-1-1,No,Required,,,Any implementation-defined behaviour on which the output of the program depends shall be documented and understood,,,, c,MISRA-C-2012,DIR-2-1,Yes,Required,,,All source files shall compile without any compilation errors,A1-4-3,Language,Medium, -c,MISRA-C-2012,RULE-3-1,No,Required,,,All code shall be traceable to documented requirements,,,, -c,MISRA-C-2012,RULE-4-1,No,Required,,,Run-time failures shall be minimized,,,, -c,MISRA-C-2012,RULE-4-2,Yes,Advisory,,,All usage of assembly language should be documented,M7-4-1,Language,Import, +c,MISRA-C-2012,DIR-3-1,No,Required,,,All code shall be traceable to documented requirements,,,, +c,MISRA-C-2012,DIR-4-1,No,Required,,,Run-time failures shall be minimized,,,, +c,MISRA-C-2012,DIR-4-2,Yes,Advisory,,,All usage of assembly language should be documented,M7-4-1,Language,Import, c,MISRA-C-2012,DIR-4-3,Yes,Required,,,Assembly language shall be encapsulated and isolated,,Language1,Medium, -c,MISRA-C-2012,RULE-4-4,Yes,Advisory,,,Sections of code should not be commented out,A2-7-2,Syntax,Import, +c,MISRA-C-2012,DIR-4-4,Yes,Advisory,,,Sections of code should not be commented out,A2-7-2,Syntax,Import, c,MISRA-C-2012,DIR-4-5,Yes,Advisory,,,Identifiers in the same name space with overlapping visibility should be typographically unambiguous,M2-10-1,Syntax,Easy, -c,MISRA-C-2012,RULE-4-6,Yes,Advisory,,,typedefs that indicate size and signedness should be used in place of the basic numerical types,,Types,Hard, -c,MISRA-C-2012,RULE-4-7,Yes,Required,,,"If a function returns error information, then that error information shall be tested",M0-3-2,Contracts,Import, -c,MISRA-C-2012,RULE-4-8,Yes,Advisory,,,"If a pointer to a structure or union is never dereferenced within a translation unit, then the implementation of the object should be hidden",,Pointers1,Medium, -c,MISRA-C-2012,RULE-4-9,Yes,Advisory,,,A function should be used in preference to a function-like macro where they are interchangeable,,Preprocessor,Medium, -c,MISRA-C-2012,RULE-4-10,Yes,Required,,,Precautions shall be taken in order to prevent the contents of a header file being included more than once,M16-2-3,Preprocessor2,Medium, -c,MISRA-C-2012,RULE-4-11,Yes,Required,,,The validity of values passed to library functions shall be checked,,Contracts,Hard, -c,MISRA-C-2012,RULE-4-12,Yes,Required,,,Dynamic memory allocation shall not be used,,Banned,Medium, -c,MISRA-C-2012,RULE-4-13,Yes,Advisory,,,Functions which are designed to provide operations on a resource should be called in an appropriate sequence,,Contracts,Hard, -c,MISRA-C-2012,RULE-4-14,Yes,Required,,,The validity of values received from external sources shall be checked,,Contracts,Hard, +c,MISRA-C-2012,DIR-4-6,Yes,Advisory,,,typedefs that indicate size and signedness should be used in place of the basic numerical types,,Types,Hard, +c,MISRA-C-2012,DIR-4-7,Yes,Required,,,"If a function returns error information, then that error information shall be tested",M0-3-2,Contracts,Import, +c,MISRA-C-2012,DIR-4-8,Yes,Advisory,,,"If a pointer to a structure or union is never dereferenced within a translation unit, then the implementation of the object should be hidden",,Pointers1,Medium, +c,MISRA-C-2012,DIR-4-9,Yes,Advisory,,,A function should be used in preference to a function-like macro where they are interchangeable,,Preprocessor,Medium, +c,MISRA-C-2012,DIR-4-10,Yes,Required,,,Precautions shall be taken in order to prevent the contents of a header file being included more than once,M16-2-3,Preprocessor2,Medium, +c,MISRA-C-2012,DIR-4-11,Yes,Required,,,The validity of values passed to library functions shall be checked,,Contracts,Hard, +c,MISRA-C-2012,DIR-4-12,Yes,Required,,,Dynamic memory allocation shall not be used,,Banned,Medium, +c,MISRA-C-2012,DIR-4-13,Yes,Advisory,,,Functions which are designed to provide operations on a resource should be called in an appropriate sequence,,Contracts,Hard, +c,MISRA-C-2012,DIR-4-14,Yes,Required,,,The validity of values received from external sources shall be checked,,Contracts,Hard, c,MISRA-C-2012,RULE-1-1,Yes,Required,,,"The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation�s translation limits",,Language,Easy, c,MISRA-C-2012,RULE-1-2,Yes,Advisory,,,Language extensions should not be used,,Language,Easy, c,MISRA-C-2012,RULE-1-3,Yes,Required,,,There shall be no occurrence of undefined or critical unspecified behaviour,,Language,Hard, From 8948215c353cb9f82c6928453d013dc8b3c34226 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Thu, 3 Nov 2022 14:04:56 -0400 Subject: [PATCH 06/16] fix path for check --- scripts/util/Get-DuplicateRules.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/util/Get-DuplicateRules.ps1 b/scripts/util/Get-DuplicateRules.ps1 index 5090f4628c..a75526179b 100644 --- a/scripts/util/Get-DuplicateRules.ps1 +++ b/scripts/util/Get-DuplicateRules.ps1 @@ -8,7 +8,7 @@ param( ) -Import-Module -Name "$PSScriptRoot\..\PSCodingStandards\CodingStandards" +Import-Module -Name "$PSScriptRoot/../PSCodingStandards\CodingStandards" # load the rules. $rules = Get-RulesFromCSV -Language $Language From 6e46513a05e4ffa6c98a784a0fe5967ea935fc44 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Thu, 3 Nov 2022 14:05:19 -0400 Subject: [PATCH 07/16] Update .github/workflows/validate-rules-csv.yml Co-authored-by: Luke Cartey <5377966+lcartey@users.noreply.github.com> --- .github/workflows/validate-rules-csv.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-rules-csv.yml b/.github/workflows/validate-rules-csv.yml index df4ec09e6b..1c6418c98f 100644 --- a/.github/workflows/validate-rules-csv.yml +++ b/.github/workflows/validate-rules-csv.yml @@ -16,7 +16,7 @@ on: jobs: validate-rules-csv: name: Validate Rules CSV - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v2 From 1c6c8c0b3e8e8cc42996fdc34ecb20dcb16914f3 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Thu, 3 Nov 2022 14:10:10 -0400 Subject: [PATCH 08/16] fix inconsistent escape --- scripts/util/Get-DuplicateRules.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/util/Get-DuplicateRules.ps1 b/scripts/util/Get-DuplicateRules.ps1 index a75526179b..d90f6fc716 100644 --- a/scripts/util/Get-DuplicateRules.ps1 +++ b/scripts/util/Get-DuplicateRules.ps1 @@ -8,7 +8,7 @@ param( ) -Import-Module -Name "$PSScriptRoot/../PSCodingStandards\CodingStandards" +Import-Module -Name "$PSScriptRoot/../PSCodingStandards/CodingStandards" # load the rules. $rules = Get-RulesFromCSV -Language $Language From 97f66579fb4581d570a05402125323e16893f33f Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 4 Nov 2022 10:27:53 -0400 Subject: [PATCH 09/16] refactor RULE-4-12 -> DIR-4-12 --- .vscode/tasks.json | 1 + .../StdLibDynamicMemoryAllocationUsed.ql | 4 ++-- .../StdLibDynamicMemoryAllocationUsed.expected | 0 .../rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.qlref | 1 + c/misra/test/rules/{RULE-4-12 => DIR-4-12}/test.c | 0 .../rules/RULE-4-12/StdLibDynamicMemoryAllocationUsed.qlref | 1 - cpp/common/src/codingstandards/cpp/exclusions/c/Banned.qll | 2 +- rule_packages/c/Banned.json | 2 +- 8 files changed, 6 insertions(+), 5 deletions(-) rename c/misra/src/rules/{RULE-4-12 => DIR-4-12}/StdLibDynamicMemoryAllocationUsed.ql (91%) rename c/misra/test/rules/{RULE-4-12 => DIR-4-12}/StdLibDynamicMemoryAllocationUsed.expected (100%) create mode 100644 c/misra/test/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.qlref rename c/misra/test/rules/{RULE-4-12 => DIR-4-12}/test.c (100%) delete mode 100644 c/misra/test/rules/RULE-4-12/StdLibDynamicMemoryAllocationUsed.qlref diff --git a/.vscode/tasks.json b/.vscode/tasks.json index d1f141cced..e2b393727f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -185,6 +185,7 @@ "type": "pickString", "options": [ "Allocations", + "Banned", "BannedFunctions", "BannedLibraries", "BannedSyntax", diff --git a/c/misra/src/rules/RULE-4-12/StdLibDynamicMemoryAllocationUsed.ql b/c/misra/src/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.ql similarity index 91% rename from c/misra/src/rules/RULE-4-12/StdLibDynamicMemoryAllocationUsed.ql rename to c/misra/src/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.ql index 84055145e3..a759a631b7 100644 --- a/c/misra/src/rules/RULE-4-12/StdLibDynamicMemoryAllocationUsed.ql +++ b/c/misra/src/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.ql @@ -1,13 +1,13 @@ /** * @id c/misra/std-lib-dynamic-memory-allocation-used - * @name RULE-4-12: Dynamic memory allocation shall not be used + * @name DIR-4-12: Dynamic memory allocation shall not be used * @description Using dynamic memory allocation and deallocation can result to undefined behavior. * This query is for the Standard Library Implementation. Any implementation outside it * will require a separate query under the same directive. * @kind problem * @precision very-high * @problem.severity error - * @tags external/misra/id/rule-4-12 + * @tags external/misra/id/dir-4-12 * security * correctness * maintainability diff --git a/c/misra/test/rules/RULE-4-12/StdLibDynamicMemoryAllocationUsed.expected b/c/misra/test/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.expected similarity index 100% rename from c/misra/test/rules/RULE-4-12/StdLibDynamicMemoryAllocationUsed.expected rename to c/misra/test/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.expected diff --git a/c/misra/test/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.qlref b/c/misra/test/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.qlref new file mode 100644 index 0000000000..b0cf5247b5 --- /dev/null +++ b/c/misra/test/rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.qlref @@ -0,0 +1 @@ +rules/DIR-4-12/StdLibDynamicMemoryAllocationUsed.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-4-12/test.c b/c/misra/test/rules/DIR-4-12/test.c similarity index 100% rename from c/misra/test/rules/RULE-4-12/test.c rename to c/misra/test/rules/DIR-4-12/test.c diff --git a/c/misra/test/rules/RULE-4-12/StdLibDynamicMemoryAllocationUsed.qlref b/c/misra/test/rules/RULE-4-12/StdLibDynamicMemoryAllocationUsed.qlref deleted file mode 100644 index a0602b1905..0000000000 --- a/c/misra/test/rules/RULE-4-12/StdLibDynamicMemoryAllocationUsed.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-4-12/StdLibDynamicMemoryAllocationUsed.ql \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/Banned.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/Banned.qll index 7a9af8467d..615b16c0ca 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/c/Banned.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/Banned.qll @@ -159,7 +159,7 @@ predicate isBannedQueryMetadata(Query query, string queryId, string ruleId) { queryId = // `@id` for the `stdLibDynamicMemoryAllocationUsed` query "c/misra/std-lib-dynamic-memory-allocation-used" and - ruleId = "RULE-4-12" + ruleId = "DIR-4-12" or query = // `Query` instance for the `octalConstantsUsed` query diff --git a/rule_packages/c/Banned.json b/rule_packages/c/Banned.json index 46032e3a68..42decbb3e3 100644 --- a/rule_packages/c/Banned.json +++ b/rule_packages/c/Banned.json @@ -304,7 +304,7 @@ ], "title": "The Standard Library functions 'bsearch' and 'qsort' of 'stdlib.h' shall not be used" }, - "RULE-4-12": { + "DIR-4-12": { "properties": { "obligation": "required" }, From feb21ceba0517273653acd35ff1d3f74474d2702 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 4 Nov 2022 11:02:52 -0400 Subject: [PATCH 10/16] Fix RULE-4-10 -> DIR-4-10 --- .../PrecautionIncludeGuardsNotProvided.ql | 24 +++++++++++++++++++ ...PrecautionIncludeGuardsNotProvided.testref | 1 + .../RULE-4-10/NonUniqueIncludeGuards.testref | 1 - .../cpp/exclusions/c/Preprocessor2.qll | 2 +- rule_packages/c/Preprocessor2.json | 2 +- 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 c/misra/src/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.ql create mode 100644 c/misra/test/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.testref delete mode 100644 c/misra/test/rules/RULE-4-10/NonUniqueIncludeGuards.testref diff --git a/c/misra/src/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.ql b/c/misra/src/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.ql new file mode 100644 index 0000000000..58ec5c80a9 --- /dev/null +++ b/c/misra/src/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.ql @@ -0,0 +1,24 @@ +/** + * @id c/misra/precaution-include-guards-not-provided + * @name DIR-4-10: Precautions shall be taken in order to prevent the contents of a header file being included more than once + * @description Using anything other than a standard include guard form can make code confusing and + * can lead to multiple or conflicting definitions. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/misra/id/dir-4-10 + * correctness + * maintainability + * readability + * external/misra/obligation/required + */ + +import cpp +import codingstandards.c.misra +import codingstandards.cpp.rules.includeguardsnotused.IncludeGuardsNotUsed + +class PrecautionIncludeGuardsNotProvidedQuery extends IncludeGuardsNotUsedSharedQuery { + PrecautionIncludeGuardsNotProvidedQuery() { + this = Preprocessor2Package::precautionIncludeGuardsNotProvidedQuery() + } +} diff --git a/c/misra/test/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.testref b/c/misra/test/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.testref new file mode 100644 index 0000000000..065354082f --- /dev/null +++ b/c/misra/test/rules/DIR-4-10/PrecautionIncludeGuardsNotProvided.testref @@ -0,0 +1 @@ +c/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-4-10/NonUniqueIncludeGuards.testref b/c/misra/test/rules/RULE-4-10/NonUniqueIncludeGuards.testref deleted file mode 100644 index e38907a2fc..0000000000 --- a/c/misra/test/rules/RULE-4-10/NonUniqueIncludeGuards.testref +++ /dev/null @@ -1 +0,0 @@ -c/common/test/rules/nonuniqueincludeguardsused/NonUniqueIncludeGuardsUsed.ql \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/Preprocessor2.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/Preprocessor2.qll index 942f633f45..f8a1c8ba3b 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/c/Preprocessor2.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/Preprocessor2.qll @@ -40,7 +40,7 @@ predicate isPreprocessor2QueryMetadata(Query query, string queryId, string ruleI queryId = // `@id` for the `precautionIncludeGuardsNotProvided` query "c/misra/precaution-include-guards-not-provided" and - ruleId = "RULE-4-10" + ruleId = "DIR-4-10" } module Preprocessor2Package { diff --git a/rule_packages/c/Preprocessor2.json b/rule_packages/c/Preprocessor2.json index 66e759c5b9..9eeb7beba8 100644 --- a/rule_packages/c/Preprocessor2.json +++ b/rule_packages/c/Preprocessor2.json @@ -63,7 +63,7 @@ ], "title": "#undef should not be used" }, - "RULE-4-10": { + "DIR-4-10": { "properties": { "obligation": "required" }, From f22c1ef0b032b0ba1ddb0d2e75d082b9f726578e Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 4 Nov 2022 11:03:02 -0400 Subject: [PATCH 11/16] delete tests --- .../PrecautionIncludeGuardsNotProvided.ql | 24 ------------------- ...PrecautionIncludeGuardsNotProvided.testref | 1 - 2 files changed, 25 deletions(-) delete mode 100644 c/misra/src/rules/RULE-4-10/PrecautionIncludeGuardsNotProvided.ql delete mode 100644 c/misra/test/rules/RULE-4-10/PrecautionIncludeGuardsNotProvided.testref diff --git a/c/misra/src/rules/RULE-4-10/PrecautionIncludeGuardsNotProvided.ql b/c/misra/src/rules/RULE-4-10/PrecautionIncludeGuardsNotProvided.ql deleted file mode 100644 index deea2afa83..0000000000 --- a/c/misra/src/rules/RULE-4-10/PrecautionIncludeGuardsNotProvided.ql +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @id c/misra/precaution-include-guards-not-provided - * @name RULE-4-10: Precautions shall be taken in order to prevent the contents of a header file being included more than once - * @description Using anything other than a standard include guard form can make code confusing and - * can lead to multiple or conflicting definitions. - * @kind problem - * @precision very-high - * @problem.severity warning - * @tags external/misra/id/rule-4-10 - * correctness - * maintainability - * readability - * external/misra/obligation/required - */ - -import cpp -import codingstandards.c.misra -import codingstandards.cpp.rules.includeguardsnotused.IncludeGuardsNotUsed - -class PrecautionIncludeGuardsNotProvidedQuery extends IncludeGuardsNotUsedSharedQuery { - PrecautionIncludeGuardsNotProvidedQuery() { - this = Preprocessor2Package::precautionIncludeGuardsNotProvidedQuery() - } -} diff --git a/c/misra/test/rules/RULE-4-10/PrecautionIncludeGuardsNotProvided.testref b/c/misra/test/rules/RULE-4-10/PrecautionIncludeGuardsNotProvided.testref deleted file mode 100644 index 065354082f..0000000000 --- a/c/misra/test/rules/RULE-4-10/PrecautionIncludeGuardsNotProvided.testref +++ /dev/null @@ -1 +0,0 @@ -c/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.ql \ No newline at end of file From 63d6bbdfc065dbd5dcf61773946f39ec55b93633 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 4 Nov 2022 12:16:05 -0400 Subject: [PATCH 12/16] fix rule-4-4 -> dir-4-4 --- .../SectionsOfCodeShallNotBeCommentedOut.ql | 4 ++-- .../SectionsOfCodeShallNotBeCommentedOut.testref | 0 cpp/common/src/codingstandards/cpp/exclusions/c/Syntax.qll | 2 +- rule_packages/c/Syntax.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename c/misra/src/rules/{RULE-4-4 => DIR-4-4}/SectionsOfCodeShallNotBeCommentedOut.ql (87%) rename c/misra/test/rules/{RULE-4-4 => DIR-4-4}/SectionsOfCodeShallNotBeCommentedOut.testref (100%) diff --git a/c/misra/src/rules/RULE-4-4/SectionsOfCodeShallNotBeCommentedOut.ql b/c/misra/src/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.ql similarity index 87% rename from c/misra/src/rules/RULE-4-4/SectionsOfCodeShallNotBeCommentedOut.ql rename to c/misra/src/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.ql index 52adbac29d..1831f211dd 100644 --- a/c/misra/src/rules/RULE-4-4/SectionsOfCodeShallNotBeCommentedOut.ql +++ b/c/misra/src/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.ql @@ -1,11 +1,11 @@ /** * @id c/misra/sections-of-code-shall-not-be-commented-out - * @name RULE-4-4: Sections of code should not be commented out + * @name DIR-4-4: Sections of code should not be commented out * @description Commented out code may become out of date leading to developer confusion. * @kind problem * @precision high * @problem.severity warning - * @tags external/misra/id/rule-4-4 + * @tags external/misra/id/dir-4-4 * maintainability * readability * correctness diff --git a/c/misra/test/rules/RULE-4-4/SectionsOfCodeShallNotBeCommentedOut.testref b/c/misra/test/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.testref similarity index 100% rename from c/misra/test/rules/RULE-4-4/SectionsOfCodeShallNotBeCommentedOut.testref rename to c/misra/test/rules/DIR-4-4/SectionsOfCodeShallNotBeCommentedOut.testref diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/Syntax.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/Syntax.qll index 8109741e20..901b6393a4 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/c/Syntax.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/Syntax.qll @@ -43,7 +43,7 @@ predicate isSyntaxQueryMetadata(Query query, string queryId, string ruleId) { queryId = // `@id` for the `sectionsOfCodeShallNotBeCommentedOut` query "c/misra/sections-of-code-shall-not-be-commented-out" and - ruleId = "RULE-4-4" + ruleId = "DIR-4-4" or query = // `Query` instance for the `identifiersInTheSameNameSpaceUnambiguous` query diff --git a/rule_packages/c/Syntax.json b/rule_packages/c/Syntax.json index 476254130b..d294c44183 100644 --- a/rule_packages/c/Syntax.json +++ b/rule_packages/c/Syntax.json @@ -62,7 +62,7 @@ ], "title": "Octal and hexadecimal escape sequences shall be terminated" }, - "RULE-4-4": { + "DIR-4-4": { "properties": { "obligation": "advisory" }, From 4c6c550b9dc55ba237a0e2cd6bf96b7d3b8dba3c Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 4 Nov 2022 12:18:38 -0400 Subject: [PATCH 13/16] 4-8 --- ...tWithNoPointerDereferenceShouldBeOpaque.ql | 4 +- ...oPointerDereferenceShouldBeOpaque.expected | 6 +++ ...thNoPointerDereferenceShouldBeOpaque.qlref | 1 + c/misra/test/rules/DIR-4-8/test.c | 46 +++++++++++++++++++ c/misra/test/rules/DIR-4-8/test.h | 10 ++++ c/misra/test/rules/DIR-4-8/test_2.c | 46 +++++++++++++++++++ c/misra/test/rules/DIR-4-8/test_shared.h | 28 +++++++++++ .../cpp/exclusions/c/Pointers1.qll | 2 +- rule_packages/c/Pointers1.json | 2 +- 9 files changed, 141 insertions(+), 4 deletions(-) rename c/misra/src/rules/{RULE-4-8 => DIR-4-8}/ObjectWithNoPointerDereferenceShouldBeOpaque.ql (89%) create mode 100644 c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.expected create mode 100644 c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref create mode 100644 c/misra/test/rules/DIR-4-8/test.c create mode 100644 c/misra/test/rules/DIR-4-8/test.h create mode 100644 c/misra/test/rules/DIR-4-8/test_2.c create mode 100644 c/misra/test/rules/DIR-4-8/test_shared.h diff --git a/c/misra/src/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql b/c/misra/src/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql similarity index 89% rename from c/misra/src/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql rename to c/misra/src/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql index 1521b9602a..56f2dd785d 100644 --- a/c/misra/src/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql +++ b/c/misra/src/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql @@ -1,13 +1,13 @@ /** * @id c/misra/object-with-no-pointer-dereference-should-be-opaque - * @name RULE-4-8: The implementation of an object shall be hidden if a pointer to its structure or union is never dereferenced within a translation unit + * @name DIR-4-8: The implementation of an object shall be hidden if a pointer to its structure or union is never dereferenced within a translation unit * @description If a pointer to a structure or union is never dereferenced within a translation * unit, then the implementation of the object should be hidden to prevent * unintentional changes. * @kind problem * @precision very-high * @problem.severity error - * @tags external/misra/id/rule-4-8 + * @tags external/misra/id/dir-4-8 * readability * maintainability * external/misra/obligation/advisory diff --git a/c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.expected b/c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.expected new file mode 100644 index 0000000000..cdbef7ca60 --- /dev/null +++ b/c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.expected @@ -0,0 +1,6 @@ +| test.c:10:8:10:9 | s4 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test.c:10:8:10:9 | s4 | s4 | test.c:0:0:0:0 | test.c | test.c | +| test.h:3:8:3:9 | s1 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test.h:3:8:3:9 | s1 | s1 | test.c:0:0:0:0 | test.c | test.c | +| test_2.c:7:8:7:9 | s2 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_2.c:7:8:7:9 | s2 | s2 | test_2.c:0:0:0:0 | test_2.c | test_2.c | +| test_shared.h:15:8:15:20 | only_test2_s2 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_shared.h:15:8:15:20 | only_test2_s2 | only_test2_s2 | test_2.c:0:0:0:0 | test_2.c | test_2.c | +| test_shared.h:19:7:19:15 | shared_u1 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_shared.h:19:7:19:15 | shared_u1 | shared_u1 | test.c:0:0:0:0 | test.c | test.c | +| test_shared.h:19:7:19:15 | shared_u1 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_shared.h:19:7:19:15 | shared_u1 | shared_u1 | test_2.c:0:0:0:0 | test_2.c | test_2.c | diff --git a/c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref b/c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref new file mode 100644 index 0000000000..4a5c410c38 --- /dev/null +++ b/c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref @@ -0,0 +1 @@ +rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql \ No newline at end of file diff --git a/c/misra/test/rules/DIR-4-8/test.c b/c/misra/test/rules/DIR-4-8/test.c new file mode 100644 index 0000000000..0b5f4d6639 --- /dev/null +++ b/c/misra/test/rules/DIR-4-8/test.c @@ -0,0 +1,46 @@ +#include "test.h" +#include "test_shared.h" +struct s3 { + int v1; + struct s3_1 { + int a; + } v2; // COMPLIANT +}; // COMPLIANT + +struct s4 { + int v1; +}; // NON_COMPLIANT + +typedef struct s3 s3_t; +typedef struct s4 s4_t; + +void *f1(struct s1 *p1) { return (void *)p1; } + +void *f2(struct s2 *p1) { + int v1 = p1->v1; + return p1; +} + +s3_t *f3(s3_t *p1) { + int v1 = p1[0].v1; + return p1; +} + +void *f4(s4_t *p1) { return p1; } + +void *f5(struct only_test1_s1 *p1) { + int v1 = p1->v1; + return (void *)p1; +} + +void *f6(struct shared_s1 *p1) { + int v1 = p1->v1; + return (void *)p1; +} + +void *f7(union shared_u1 *p1) { return (void *)p1; } + +void *f8(union shared_u2 *p1) { + int v1 = p1->v1; + return (void *)p1; +} \ No newline at end of file diff --git a/c/misra/test/rules/DIR-4-8/test.h b/c/misra/test/rules/DIR-4-8/test.h new file mode 100644 index 0000000000..30ff6ca33e --- /dev/null +++ b/c/misra/test/rules/DIR-4-8/test.h @@ -0,0 +1,10 @@ +#ifndef TEST_H_ +#define TEST_H_ +struct s1 { + int v1; +}; // NON_COMPLIANT + +struct s2 { + int v1; +}; // COMPLIANT +#endif // TEST_H_ \ No newline at end of file diff --git a/c/misra/test/rules/DIR-4-8/test_2.c b/c/misra/test/rules/DIR-4-8/test_2.c new file mode 100644 index 0000000000..84328bb5f5 --- /dev/null +++ b/c/misra/test/rules/DIR-4-8/test_2.c @@ -0,0 +1,46 @@ +#include "test_shared.h" + +struct s1 { + float v1; +}; // COMPLIANT + +struct s2 { + float v1; +}; // NON_COMPLIANT + +struct s3 { + float v1; +}; // COMPLIANT + +void *f1(struct s1 *p1) { + int v1 = p1->v1; + return (void *)p1; +} + +void *f2(struct s2 *p1) { return (void *)p1; } + +void *f3(struct only_test2_s1 *p1) { + int v1 = (*p1).v1; + return (void *)p1; +} + +void *f4(struct only_test2_s1 *p1) { + int v1 = p1->v1; + return (void *)p1; +} + +void *f5(struct only_test2_s2 *p1) { return (void *)p1; } + +void *f6(union shared_u1 *p1) { return (void *)p1; } + +void *f7(union shared_u2 *p1) { + int v1 = p1->v1; + return (void *)p1; +} + +void *f8(void) { + struct s3 v1; + return (void *)0; +} + +void *f9(struct s3 *p1) { return (void *)p1; } \ No newline at end of file diff --git a/c/misra/test/rules/DIR-4-8/test_shared.h b/c/misra/test/rules/DIR-4-8/test_shared.h new file mode 100644 index 0000000000..c3c44fc43b --- /dev/null +++ b/c/misra/test/rules/DIR-4-8/test_shared.h @@ -0,0 +1,28 @@ +#ifndef TEST_SHARED_H_ +#define TEST_SHARED_H_ +struct shared_s1 { + int v1; +}; // COMPLIANT + +struct only_test1_s1 { + int v1; +}; // COMPLIANT + +struct only_test2_s1 { + int v1; +}; // COMPLIANT + +struct only_test2_s2 { + int v1; +}; // NON_COMPLIANT + +union shared_u1 { + int v1; + float v2; +}; // NON_COMPLIANT + +union shared_u2 { + int v1; + float v2; +}; // COMPLIANT +#endif // TEST_SHARED_H_ \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/exclusions/c/Pointers1.qll b/cpp/common/src/codingstandards/cpp/exclusions/c/Pointers1.qll index 506e3a5fba..11daf5543c 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/c/Pointers1.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/c/Pointers1.qll @@ -149,7 +149,7 @@ predicate isPointers1QueryMetadata(Query query, string queryId, string ruleId) { queryId = // `@id` for the `objectWithNoPointerDereferenceShouldBeOpaque` query "c/misra/object-with-no-pointer-dereference-should-be-opaque" and - ruleId = "RULE-4-8" + ruleId = "DIR-4-8" or query = // `Query` instance for the `pointerShouldPointToConstTypeWhenPossible` query diff --git a/rule_packages/c/Pointers1.json b/rule_packages/c/Pointers1.json index 991838e34f..6b2df1595c 100644 --- a/rule_packages/c/Pointers1.json +++ b/rule_packages/c/Pointers1.json @@ -294,7 +294,7 @@ ], "title": "The address of an object with automatic storage shall not be copied to another object that persists after the first object has ceased to exist" }, - "RULE-4-8": { + "DIR-4-8": { "properties": { "obligation": "advisory" }, From fd33c17f10535a5a2b620baafcb262cf87cf2102 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 4 Nov 2022 12:18:47 -0400 Subject: [PATCH 14/16] 4-8 --- ...oPointerDereferenceShouldBeOpaque.expected | 6 --- ...thNoPointerDereferenceShouldBeOpaque.qlref | 1 - c/misra/test/rules/RULE-4-8/test.c | 46 ------------------- c/misra/test/rules/RULE-4-8/test.h | 10 ---- c/misra/test/rules/RULE-4-8/test_2.c | 46 ------------------- c/misra/test/rules/RULE-4-8/test_shared.h | 28 ----------- 6 files changed, 137 deletions(-) delete mode 100644 c/misra/test/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.expected delete mode 100644 c/misra/test/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref delete mode 100644 c/misra/test/rules/RULE-4-8/test.c delete mode 100644 c/misra/test/rules/RULE-4-8/test.h delete mode 100644 c/misra/test/rules/RULE-4-8/test_2.c delete mode 100644 c/misra/test/rules/RULE-4-8/test_shared.h diff --git a/c/misra/test/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.expected b/c/misra/test/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.expected deleted file mode 100644 index cdbef7ca60..0000000000 --- a/c/misra/test/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.expected +++ /dev/null @@ -1,6 +0,0 @@ -| test.c:10:8:10:9 | s4 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test.c:10:8:10:9 | s4 | s4 | test.c:0:0:0:0 | test.c | test.c | -| test.h:3:8:3:9 | s1 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test.h:3:8:3:9 | s1 | s1 | test.c:0:0:0:0 | test.c | test.c | -| test_2.c:7:8:7:9 | s2 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_2.c:7:8:7:9 | s2 | s2 | test_2.c:0:0:0:0 | test_2.c | test_2.c | -| test_shared.h:15:8:15:20 | only_test2_s2 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_shared.h:15:8:15:20 | only_test2_s2 | only_test2_s2 | test_2.c:0:0:0:0 | test_2.c | test_2.c | -| test_shared.h:19:7:19:15 | shared_u1 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_shared.h:19:7:19:15 | shared_u1 | shared_u1 | test.c:0:0:0:0 | test.c | test.c | -| test_shared.h:19:7:19:15 | shared_u1 | $@ is not opaque but no pointer to it is dereferenced within the translation unit $@. | test_shared.h:19:7:19:15 | shared_u1 | shared_u1 | test_2.c:0:0:0:0 | test_2.c | test_2.c | diff --git a/c/misra/test/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref b/c/misra/test/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref deleted file mode 100644 index 4a5c410c38..0000000000 --- a/c/misra/test/rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql \ No newline at end of file diff --git a/c/misra/test/rules/RULE-4-8/test.c b/c/misra/test/rules/RULE-4-8/test.c deleted file mode 100644 index 0b5f4d6639..0000000000 --- a/c/misra/test/rules/RULE-4-8/test.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "test.h" -#include "test_shared.h" -struct s3 { - int v1; - struct s3_1 { - int a; - } v2; // COMPLIANT -}; // COMPLIANT - -struct s4 { - int v1; -}; // NON_COMPLIANT - -typedef struct s3 s3_t; -typedef struct s4 s4_t; - -void *f1(struct s1 *p1) { return (void *)p1; } - -void *f2(struct s2 *p1) { - int v1 = p1->v1; - return p1; -} - -s3_t *f3(s3_t *p1) { - int v1 = p1[0].v1; - return p1; -} - -void *f4(s4_t *p1) { return p1; } - -void *f5(struct only_test1_s1 *p1) { - int v1 = p1->v1; - return (void *)p1; -} - -void *f6(struct shared_s1 *p1) { - int v1 = p1->v1; - return (void *)p1; -} - -void *f7(union shared_u1 *p1) { return (void *)p1; } - -void *f8(union shared_u2 *p1) { - int v1 = p1->v1; - return (void *)p1; -} \ No newline at end of file diff --git a/c/misra/test/rules/RULE-4-8/test.h b/c/misra/test/rules/RULE-4-8/test.h deleted file mode 100644 index 30ff6ca33e..0000000000 --- a/c/misra/test/rules/RULE-4-8/test.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef TEST_H_ -#define TEST_H_ -struct s1 { - int v1; -}; // NON_COMPLIANT - -struct s2 { - int v1; -}; // COMPLIANT -#endif // TEST_H_ \ No newline at end of file diff --git a/c/misra/test/rules/RULE-4-8/test_2.c b/c/misra/test/rules/RULE-4-8/test_2.c deleted file mode 100644 index 84328bb5f5..0000000000 --- a/c/misra/test/rules/RULE-4-8/test_2.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "test_shared.h" - -struct s1 { - float v1; -}; // COMPLIANT - -struct s2 { - float v1; -}; // NON_COMPLIANT - -struct s3 { - float v1; -}; // COMPLIANT - -void *f1(struct s1 *p1) { - int v1 = p1->v1; - return (void *)p1; -} - -void *f2(struct s2 *p1) { return (void *)p1; } - -void *f3(struct only_test2_s1 *p1) { - int v1 = (*p1).v1; - return (void *)p1; -} - -void *f4(struct only_test2_s1 *p1) { - int v1 = p1->v1; - return (void *)p1; -} - -void *f5(struct only_test2_s2 *p1) { return (void *)p1; } - -void *f6(union shared_u1 *p1) { return (void *)p1; } - -void *f7(union shared_u2 *p1) { - int v1 = p1->v1; - return (void *)p1; -} - -void *f8(void) { - struct s3 v1; - return (void *)0; -} - -void *f9(struct s3 *p1) { return (void *)p1; } \ No newline at end of file diff --git a/c/misra/test/rules/RULE-4-8/test_shared.h b/c/misra/test/rules/RULE-4-8/test_shared.h deleted file mode 100644 index c3c44fc43b..0000000000 --- a/c/misra/test/rules/RULE-4-8/test_shared.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TEST_SHARED_H_ -#define TEST_SHARED_H_ -struct shared_s1 { - int v1; -}; // COMPLIANT - -struct only_test1_s1 { - int v1; -}; // COMPLIANT - -struct only_test2_s1 { - int v1; -}; // COMPLIANT - -struct only_test2_s2 { - int v1; -}; // NON_COMPLIANT - -union shared_u1 { - int v1; - float v2; -}; // NON_COMPLIANT - -union shared_u2 { - int v1; - float v2; -}; // COMPLIANT -#endif // TEST_SHARED_H_ \ No newline at end of file From 2dede330c9d8e6d1a71665df3de3cefcc3ce134b Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 4 Nov 2022 12:21:57 -0400 Subject: [PATCH 15/16] changenotes --- change_notes/2022-11-04-refactor-dir-rules.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 change_notes/2022-11-04-refactor-dir-rules.md diff --git a/change_notes/2022-11-04-refactor-dir-rules.md b/change_notes/2022-11-04-refactor-dir-rules.md new file mode 100644 index 0000000000..303f718ddd --- /dev/null +++ b/change_notes/2022-11-04-refactor-dir-rules.md @@ -0,0 +1,9 @@ +- The following rules have been renamed: + - RULE-4-4 has been renamed to DIR-4-4 to reflect correct naming as per + MISRA C:2012 standard. + - RULE-4-8 has been renamed to DIR-4-8 to reflect correct naming as per + MISRA C:2012 standard. + - RULE-4-10 has been renamed to DIR-4-10 to reflect correct naming as per + MISRA C:2012 standard. + - RULE-4-12 has been renamed to DIR-4-12 to reflect correct naming as per + MISRA C:2012 standard. \ No newline at end of file From b303d0ed4ab0cc299eff5c6e7ca7345ce2071e4e Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Fri, 4 Nov 2022 12:24:56 -0400 Subject: [PATCH 16/16] missed this --- .../DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref b/c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref index 4a5c410c38..dfa03268cf 100644 --- a/c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref +++ b/c/misra/test/rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.qlref @@ -1 +1 @@ -rules/RULE-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql \ No newline at end of file +rules/DIR-4-8/ObjectWithNoPointerDereferenceShouldBeOpaque.ql \ No newline at end of file