Skip to content

Commit aab3a88

Browse files
committed
Pointers: 0 is a null pointer constant
According to MISRA C 2012 8.11 zero is a null pointer constant, and so should not be flagged as non_compliant.
1 parent 23e25b9 commit aab3a88

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

c/common/src/codingstandards/c/Pointers.qll

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,7 @@ class ArrayPointerArithmeticExpr extends PointerArithmeticExpr, ArrayExpr {
6262
predicate isNullPointerConstant(Expr e) {
6363
e.findRootCause() instanceof NULLMacro
6464
or
65-
exists(CStyleCast c |
66-
not c.isImplicit() and
67-
c.getExpr() = e and
68-
e instanceof Zero and
69-
c.getType() instanceof VoidPointerType
70-
)
65+
e instanceof Zero
7166
or
7267
isNullPointerConstant(e.(Conversion).getExpr())
7368
}
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
| test.c:5:21:5:42 | (unsigned int)... | Cast performed between a pointer to object type and a pointer to an integer type. |
2-
| test.c:5:35:5:42 | (int *)... | Cast performed between a pointer to object type and a pointer to an integer type. |
31
| test.c:6:21:6:37 | (unsigned int)... | Cast performed between a pointer to object type and a pointer to an integer type. |
42
| test.c:8:8:8:24 | (unsigned int)... | Cast performed between a pointer to object type and a pointer to an integer type. |
5-
| test.c:10:22:10:22 | (unsigned int *)... | Cast performed between a pointer to object type and a pointer to an integer type. |
63
| test.c:12:22:12:39 | (unsigned int *)... | Cast performed between a pointer to object type and a pointer to an integer type. |

c/misra/test/rules/RULE-11-4/test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
void f1(void) {
44
unsigned int v1 = (unsigned int)(void *)0; // COMPLIANT
5-
unsigned int v2 = (unsigned int)(int *)0; // NON_COMPLIANT
5+
unsigned int v2 = (unsigned int)(int *)0; // COMPLIANT
66
unsigned int v3 = (unsigned int)&v2; // NON_COMPLIANT
77
v3 = v2; // COMPLIANT
88
v3 = (unsigned int)&v2; // NON_COMPLIANT
99
v3 = NULL; // COMPLIANT
10-
unsigned int *v4 = 0; // NON_COMPLIANT
10+
unsigned int *v4 = 0; // COMPLIANT
1111
unsigned int *v5 = NULL; // COMPLIANT
1212
unsigned int *v6 = (unsigned int *)v2; // NON_COMPLIANT
1313
}

0 commit comments

Comments
 (0)