Skip to content

Commit 410895c

Browse files
Merge remote-tracking branch 'origin/michaelrfairhurst/package-undefined-behavior' into michaelrfairhurst/package-undefined-behavior-cast-enum-out-of-range
2 parents 38cf430 + 2756406 commit 410895c

File tree

41 files changed

+380
-46
lines changed

Some content is hidden

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

41 files changed

+380
-46
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A2-13-4` - `StringLiteralsAssignedToNonConstantPointers.ql`:
2+
- Refactored query logic into a shared module (`StringLiteralsAssignedToNonConstantPointersShared`) to enable reuse by MISRA C++ `RULE-4-1-3`. The query logic is unchanged. No visible changes to results or performance are expected.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `MEM51-CPP` - `ProperlyDeallocateDynamicallyAllocatedResources.ql`:
2+
- Refactored query logic into a shared library (`ProperlyDeallocateDynamicallyAllocatedResourcesShared.qll`) to enable reuse by MISRA C++ `RULE-4-1-3`. The query logic is unchanged and no visible changes to results or performance are expected.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A5-6-1` - `DivisorEqualToZero.ql`:
2+
- Refactored query logic into a shared library (`DivisorEqualToZeroShared.qll`) to enable reuse by MISRA C++ `RULE-4-1-3`. The query logic is unchanged and no visible changes to results or performance are expected.

cpp/autosar/src/rules/A2-13-4/StringLiteralsAssignedToNonConstantPointers.ql

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
import cpp
1919
import codingstandards.cpp.autosar
20+
import codingstandards.cpp.rules.stringliteralsassignedtononconstantpointersshared.StringLiteralsAssignedToNonConstantPointersShared
2021

21-
from ArrayToPointerConversion apc
22-
where
23-
not isExcluded(apc, StringsPackage::stringLiteralsAssignedToNonConstantPointersQuery()) and
24-
apc.getExpr() instanceof StringLiteral and
25-
apc.getExpr().getUnderlyingType().(ArrayType).getBaseType().isConst() and
26-
not apc.getFullyConverted().getType().getUnderlyingType().(PointerType).getBaseType().isConst()
27-
select apc, "String literal assigned to non-const pointer."
22+
module StringLiteralsAssignedToNonConstantPointersConfig implements
23+
StringLiteralsAssignedToNonConstantPointersSharedConfigSig
24+
{
25+
Query getQuery() { result = StringsPackage::stringLiteralsAssignedToNonConstantPointersQuery() }
26+
}
27+
28+
import StringLiteralsAssignedToNonConstantPointersShared<StringLiteralsAssignedToNonConstantPointersConfig>

cpp/autosar/src/rules/A5-6-1/DivisorEqualToZero.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
import cpp
1717
import codingstandards.cpp.autosar
18+
import codingstandards.cpp.rules.divisorequaltozeroshared.DivisorEqualToZeroShared
1819

19-
from BinaryArithmeticOperation bao
20-
where
21-
not isExcluded(bao, ExpressionsPackage::divisorEqualToZeroQuery()) and
22-
(bao instanceof DivExpr or bao instanceof RemExpr) and
23-
bao.getRightOperand().getValue().toFloat() = 0 // `toFloat()` holds for both integer and float literals.
24-
select bao, "Divisor is zero."
20+
module DivisorEqualToZeroConfig implements DivisorEqualToZeroSharedConfigSig {
21+
Query getQuery() { result = ExpressionsPackage::divisorEqualToZeroQuery() }
22+
}
23+
24+
import DivisorEqualToZeroShared<DivisorEqualToZeroConfig>

cpp/autosar/test/rules/A2-13-4/StringLiteralsAssignedToNonConstantPointers.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/stringliteralsassignedtononconstantpointersshared/StringLiteralsAssignedToNonConstantPointersShared.ql

cpp/autosar/test/rules/A5-6-1/DivisorEqualToZero.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/divisorequaltozeroshared/DivisorEqualToZeroShared.ql

cpp/cert/src/rules/MEM51-CPP/ProperlyDeallocateDynamicallyAllocatedResources.ql

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@
1919

2020
import cpp
2121
import codingstandards.cpp.cert
22-
import codingstandards.cpp.Allocations
22+
import codingstandards.cpp.rules.properlydeallocatedynamicallyallocatedresourcesshared.ProperlyDeallocateDynamicallyAllocatedResourcesShared
2323

24-
predicate matching(string allocKind, string deleteKind) {
25-
allocKind = "new" and deleteKind = "delete"
26-
or
27-
allocKind = "new[]" and deleteKind = "delete[]"
28-
or
29-
allocKind = "malloc" and deleteKind = "free"
24+
module ProperlyDeallocateDynamicallyAllocatedResourcesConfig implements
25+
ProperlyDeallocateDynamicallyAllocatedResourcesSharedConfigSig
26+
{
27+
Query getQuery() {
28+
result = AllocationsPackage::properlyDeallocateDynamicallyAllocatedResourcesQuery()
29+
}
3030
}
3131

32-
from Expr alloc, Expr free, Expr freed, string allocKind, string deleteKind
33-
where
34-
not isExcluded(freed, AllocationsPackage::properlyDeallocateDynamicallyAllocatedResourcesQuery()) and
35-
allocReaches(freed, alloc, allocKind) and
36-
freeExprOrIndirect(free, freed, deleteKind) and
37-
not matching(allocKind, deleteKind)
38-
select free, "Memory allocated with $@ but deleted with " + deleteKind + ".", alloc, allocKind
32+
import ProperlyDeallocateDynamicallyAllocatedResourcesShared<ProperlyDeallocateDynamicallyAllocatedResourcesConfig>

0 commit comments

Comments
 (0)