Skip to content

Commit 36092b7

Browse files
committed
Fix FP for MISRA-C RULE-13-4
1 parent 53b21c4 commit 36092b7

5 files changed

Lines changed: 30 additions & 2 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
| test.c:9:7:9:12 | ... = ... | Use of an assignment operator's result. |
22
| test.c:13:11:13:16 | ... = ... | Use of an assignment operator's result. |
33
| test.c:15:8:15:13 | ... = ... | Use of an assignment operator's result. |
4+
| test.c:17:6:17:13 | ... += ... | Use of an assignment operator's result. |

c/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,15 @@ void test() {
1313
l1 = l3[l2 = 0]; // NON_COMPLIANT
1414

1515
l1 = l2 = 0; // NON_COMPLIANT
16+
17+
l3[l1 += l2] = l3[l1]; // NON_COMPLIANT
18+
19+
for (l1 = 0; l1 < 10; l1 += l2) // COMPLIANT
20+
{
21+
}
22+
23+
while (l1 < 10) // COMPLIANT
24+
{
25+
l1 += l2; // COMPLIANT
26+
}
1627
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- `RULE-13-4` - `ResultOfAnAssignmentOperatorShouldNotBeUsed`:
2+
- Fixed false positives.
3+
- `RULE-8-18-2` - `ResultOfAnAssignmentOperatorShouldNotBeUsed`:
4+
- Fixed false positives.

cpp/common/src/codingstandards/cpp/rules/resultofanassignmentoperatorshouldnotbeused/ResultOfAnAssignmentOperatorShouldNotBeUsed.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ abstract class ResultOfAnAssignmentOperatorShouldNotBeUsedSharedQuery extends Qu
1111

1212
Query getQuery() { result instanceof ResultOfAnAssignmentOperatorShouldNotBeUsedSharedQuery }
1313

14-
query predicate problems(AssignExpr e, string message) {
14+
query predicate problems(Assignment e, string message) {
1515
not isExcluded(e, getQuery()) and
1616
not exists(ExprStmt s | s.getExpr() = e) and
17+
not exists(ForStmt for | for.getUpdate() = e) and
1718
message = "Use of an assignment operator's result."
1819
}

cpp/common/test/rules/resultofanassignmentoperatorshouldnotbeused/test.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,15 @@ void test() {
1313
l1 = l3[l2 = 0]; // NON_COMPLIANT
1414

1515
l1 = l2 = 0; // NON_COMPLIANT
16-
}
16+
17+
l3[l1 += l2] = l3[l1]; // NON_COMPLIANT
18+
19+
for (l1 = 0; l1 < 10; l1 += l2) // COMPLIANT
20+
{
21+
}
22+
23+
while (l1 < 10) // COMPLIANT
24+
{
25+
l1 += l2; // COMPLIANT
26+
}
27+
}

0 commit comments

Comments
 (0)