Skip to content

Commit 9748585

Browse files
committed
added RULE-14-4 and moved A5-0-2 to shared folder
1 parent df09cc1 commit 9748585

27 files changed

+208
-75
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.c:7:7:7:8 | l1 | If condition has non boolean type int. |
2+
| test.c:9:7:9:8 | call to f1 | If condition has non boolean type int. |
3+
| test.c:12:7:12:8 | l2 | If condition has non boolean type void *. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.nonbooleanifstmt.NonBooleanIfStmt
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "stdbool.h"
2+
int f1();
3+
void *f2();
4+
5+
void f3() {
6+
int l1 = 1;
7+
if (l1) { // NON_COMPLIANT
8+
}
9+
if (f1()) { // NON_COMPLIANT
10+
}
11+
void *l2 = f2();
12+
if (l2) { // NON_COMPLIANT
13+
}
14+
}
15+
16+
void f4() {
17+
int l1 = 1;
18+
if ((bool)l1) { // COMPLIANT
19+
}
20+
21+
int l2 = 1;
22+
if ((const bool)l2) { // COMPLIANT
23+
}
24+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.c:5:3:6:3 | for(...;...;...) ... | Iteration condition has non boolean type int. |
2+
| test.c:7:3:8:3 | while (...) ... | Iteration condition has non boolean type int. |
3+
| test.c:13:3:14:3 | for(...;...;...) ... | Iteration condition has non boolean type int. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.nonbooleaniterationstmt.NonBooleanIterationStmt
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
void f1() {
4+
int l1;
5+
for (int i = 10; i; i++) { // NON_COMPLIANT
6+
}
7+
while (l1) { // NON_COMPLIANT
8+
}
9+
}
10+
11+
void f2() {
12+
int j = 0;
13+
for (int i = 0; i < 10; i++) { // COMPLIANT
14+
}
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @id c/misra/non-boolean-if-condition
3+
* @name RULE-14-4: The condition of an if-statement shall have type bool
4+
* @description Non boolean conditions can be confusing for developers.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity recommendation
8+
* @tags external/misra/id/rule-14-4
9+
* maintainability
10+
* readability
11+
* external/misra/obligation/required
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.rules.nonbooleanifstmt.NonBooleanIfStmt
17+
18+
class NonBooleanIfConditionQuery extends NonBooleanIfStmtSharedQuery {
19+
NonBooleanIfConditionQuery() {
20+
this = Statements4Package::nonBooleanIfConditionQuery()
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @id c/misra/non-boolean-iteration-condition
3+
* @name RULE-14-4: The condition of an iteration statement shall have type bool
4+
* @description Non boolean conditions can be confusing for developers.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity recommendation
8+
* @tags external/misra/id/rule-14-4
9+
* maintainability
10+
* readability
11+
* external/misra/obligation/required
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.rules.nonbooleaniterationstmt.NonBooleanIterationStmt
17+
18+
class NonBooleanIterationConditionQuery extends NonBooleanIterationStmtSharedQuery {
19+
NonBooleanIterationConditionQuery() {
20+
this = Statements4Package::nonBooleanIterationConditionQuery()
21+
}
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c/common/test/rules/nonbooleanifstmt/NonBooleanIfStmt.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c/common/test/rules/nonbooleaniterationstmt/NonBooleanIterationStmt.ql

0 commit comments

Comments
 (0)