Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc55a173

Browse files
First round of feedback
1 parentbfa67c1 commitc55a173

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

‎change_notes/2025-1-04-misra-c-technical-corrigenda-2.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-`RULE-8-3` -`DeclarationsOfAFunctionSameNameAndType.ql`:
22
- Implement new exception, unnamed parameters are not covered by this rule.
3-
-`RULE-10-2` -`AdditionSubtractionOnEssentiallCharType.ql`:
3+
-`RULE-10-2` -`AdditionSubtractionOnEssentiallyCharType.ql`:
44
- Disallow`+` and`-` operations with an essentially char type and other types larger than int type.
55
- Note, this change affects the essential type of such expressions, which may affect other essential types rules.
66
-`RULE-18-1`,`M5-0-16` -`PointerAndDerivedPointerMustAddressSameArray.ql`,`PointerAndDerivedPointerAccessDifferentArray.ql`:

‎cpp/common/src/codingstandards/cpp/rules/donotusepointerarithmetictoaddressdifferentarrays/DoNotUsePointerArithmeticToAddressDifferentArrays.qll‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,28 @@ class CastedToBytePointer extends ArrayLikeAccess, Conversion {
104104
}
105105
}
106106

107+
predicatepointerRecastBarrier(DataFlow::Nodebarrier){
108+
// Casting to a differently sized pointer
109+
exists(CStyleCastcast,Exprcasted|
110+
cast.getExpr()=castedandcasted=barrier.asConvertedExpr()
111+
|
112+
notcasted.getType().(PointerType).getBaseType().getSize()=
113+
cast.getType().(PointerType).getBaseType().getSize()
114+
)
115+
}
116+
107117
/**
108118
* A data-flow configuration that tracks access to an array to type to an array index expression.
109119
* This is used to determine possible pointer to array creations.
110120
*/
111121
module ByteArrayToArrayExprConfigimplements DataFlow::ConfigSig{
112122
predicateisSource(DataFlow::Nodesource){exists(CastedToBytePointera|a.getNode()=source)}
113123

114-
// TODO: casting to different size pointed-to-type invalidates
124+
predicateisBarrier(DataFlow::Nodebarrier){
125+
// Casting to a differently sized pointer invalidates this analysis.
126+
pointerRecastBarrier(barrier)
127+
}
128+
115129
predicateisSink(DataFlow::Nodesink){exists(ArrayExprc|c.getArrayBase()=sink.asExpr())}
116130
}
117131

@@ -126,12 +140,7 @@ module ArrayToArrayExprConfig implements DataFlow::ConfigSig {
126140

127141
predicateisBarrier(DataFlow::Nodebarrier){
128142
// Casting to a differently sized pointer invalidates this analysis.
129-
exists(CStyleCastcast,Exprcasted|
130-
cast.getExpr()=castedandcasted=barrier.asConvertedExpr()
131-
|
132-
notcasted.getType().(PointerType).getBaseType().getSize()=
133-
cast.getType().(PointerType).getBaseType().getSize()
134-
)
143+
pointerRecastBarrier(barrier)
135144
}
136145

137146
predicateisSink(DataFlow::Nodesink){exists(ArrayExprc|c.getArrayBase()=sink.asExpr())}

‎cpp/common/test/rules/donotusepointerarithmetictoaddressdifferentarrays/test.cpp‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ void f1() {
4040
void *p22 = &p21[0];// COMPLIANT
4141
void *p23 = &p21[100];// NON_COMPLIANT[FALSE_NEGATIVE]
4242

43+
// Casting a byte pointer to a differently sized type that isn't char
44+
// invalidates analysis
45+
long *p24 = (long *)p15;
46+
void *p25 = &p24[0];// COMPLIANT
47+
void *p26 = &p24[100];// NON_COMPLIANT[FALSE_NEGATIVE]
48+
4349
// Void pointers have size zero and can't be analyzed.
44-
void *p24 =0;
45-
unsignedchar *p25 = (unsignedchar *)p24;
46-
void *p26 = &p25[100];// COMPLIANT
50+
void *p27 =0;
51+
unsignedchar *p28 = (unsignedchar *)p27;
52+
void *p29 = &p28[100];// COMPLIANT
4753
}

‎rule_packages/c/Statements5.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
]
2121
}
2222
],
23+
"implementation_scope": {
24+
"description":"Not all invariant logical expressions which contain dynamic values are detected to be invariant, for instance, `x < 3 && x > 5` where x does not have a statically known value."
25+
},
2326
"title":"Controlling expressions shall not be invariant"
2427
},
2528
"RULE-15-5": {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp