Skip to content

Commit cb45556

Browse files
committed
Update queries and .expected for DIR-4-6
1 parent 1408a85 commit cb45556

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

c/misra/src/rules/DIR-4-6/PlainNumericalTypeUsedOverExplicitTypedef.ql

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import cpp
1414
import codingstandards.c.misra
1515

16-
abstract class ForbiddenType extends Type { }
17-
18-
class BuiltinNumericType extends ForbiddenType {
16+
class BuiltinNumericType extends BuiltInType {
1917
BuiltinNumericType() {
2018
/* Exclude the plain char because it does not count as a numeric type */
2119
this.(CharType).isExplicitlySigned()
@@ -38,15 +36,22 @@ class BuiltinNumericType extends ForbiddenType {
3836
}
3937
}
4038

41-
class ForbiddenTypedefType extends ForbiddenType, TypedefType {
42-
ForbiddenTypedefType() {
43-
this.(TypedefType).getBaseType() instanceof BuiltinNumericType and
44-
not this.getName().regexpMatch("u?(int|float)(4|8|16|32|64|128)_t")
45-
}
39+
predicate forbiddenBuiltinNumericUsedInDecl(Variable var, string message) {
40+
var.getType() instanceof BuiltinNumericType and
41+
message = "The type " + var.getType() + " is not a fixed-width numeric type."
42+
}
43+
44+
predicate forbiddenTypedef(TypedefType typedef, string message) {
45+
typedef.getBaseType() instanceof BuiltinNumericType and
46+
not typedef.getName().regexpMatch("u?(int|float)(4|8|16|32|64|128)_t") and
47+
message = "The type " + typedef.getName() + " is not an alias to a fixed-width numeric type."
4648
}
4749

48-
/* TODO: BuiltinNumericType not being flagged */
49-
from ForbiddenType forbiddenType
50-
where not isExcluded(forbiddenType, TypesPackage::plainNumericalTypeUsedOverExplicitTypedefQuery())
51-
select forbiddenType,
52-
"The type " + forbiddenType + " is not a fixed-width numeric type nor an alias to one."
50+
from Element elem, string message
51+
where
52+
not isExcluded(elem, TypesPackage::plainNumericalTypeUsedOverExplicitTypedefQuery()) and
53+
(
54+
forbiddenBuiltinNumericUsedInDecl(elem, message) or
55+
forbiddenTypedef(elem, message)
56+
)
57+
select elem, message
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
No expected results have yet been specified
1+
| test.c:27:5:27:26 | _astronomical_number_t | The type _astronomical_number_t is not an alias to a fixed-width numeric type. |
2+
| test.c:30:10:30:13 | argc | The type int is not a fixed-width numeric type. |
3+
| test.c:34:15:34:16 | c2 | The type signed char is not a fixed-width numeric type. |
4+
| test.c:35:17:35:18 | c3 | The type unsigned char is not a fixed-width numeric type. |
5+
| test.c:38:9:38:10 | s1 | The type short is not a fixed-width numeric type. |
6+
| test.c:39:16:39:17 | s2 | The type signed short is not a fixed-width numeric type. |
7+
| test.c:40:18:40:19 | s3 | The type unsigned short is not a fixed-width numeric type. |
8+
| test.c:43:7:43:8 | i1 | The type int is not a fixed-width numeric type. |
9+
| test.c:44:14:44:15 | i2 | The type signed int is not a fixed-width numeric type. |
10+
| test.c:45:16:45:17 | i3 | The type unsigned int is not a fixed-width numeric type. |
11+
| test.c:48:8:48:9 | l1 | The type long is not a fixed-width numeric type. |
12+
| test.c:49:15:49:16 | l2 | The type signed long is not a fixed-width numeric type. |
13+
| test.c:50:17:50:18 | l3 | The type unsigned long is not a fixed-width numeric type. |
14+
| test.c:53:13:53:15 | ll1 | The type long long is not a fixed-width numeric type. |
15+
| test.c:54:20:54:22 | ll2 | The type signed long long is not a fixed-width numeric type. |
16+
| test.c:55:22:55:24 | ll3 | The type unsigned long long is not a fixed-width numeric type. |
17+
| test.c:58:9:58:10 | f1 | The type float is not a fixed-width numeric type. |
18+
| test.c:61:10:61:11 | d1 | The type double is not a fixed-width numeric type. |
19+
| test.c:64:15:64:17 | ld1 | The type long double is not a fixed-width numeric type. |

0 commit comments

Comments
 (0)