Skip to content

Commit d4ed99e

Browse files
committed
// Ignore realloc, as that memory may already be partially constructed
RULE-11-5: Handle const pointers
1 parent c353b28 commit d4ed99e

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

c/misra/src/rules/RULE-11-5/ConversionFromPointerToVoidIntoPointerToObject.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import codingstandards.cpp.Pointers
1919
from Cast cast, VoidPointerType type, PointerToObjectType newType
2020
where
2121
not isExcluded(cast, Pointers1Package::conversionFromPointerToVoidIntoPointerToObjectQuery()) and
22-
type = cast.getExpr().getUnderlyingType() and
22+
type = cast.getExpr().getUnspecifiedType() and
2323
newType = cast.getUnderlyingType() and
2424
not isNullPointerConstant(cast.getExpr())
2525
select cast,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
| test.c:6:13:6:21 | (int *)... | Cast performed from a void pointer into a pointer to an object (int *). |
2+
| test.c:11:3:11:11 | (int *)... | Cast performed from a void pointer into a pointer to an object (int *). |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void f1(void) {
88
void *v3 = (void *)v1; // COMPLIANT
99
v3 = (void *)v2; // COMPLIANT
1010
const void *v4 = 0;
11-
(int *)v4; // NON_COMPLIANT[FALSE_NEGATIVE] - const in type is irrelevant
11+
(int *)v4; // NON_COMPLIANT - const in type is irrelevant
1212
(const void *)v1; // COMPLIANT - casting is from void to void, const addition
1313
// should be irrelevant
1414
}

0 commit comments

Comments
 (0)