Skip to content

Commit 83e57be

Browse files
committed
Rule 8.2.8: Improve CodeQL query
- Remove redundant code - Use stripSpecifiers(..) to check for use of (u)intptr_t.
1 parent a065203 commit 83e57be

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

cpp/misra/src/rules/RULE-8-2-8/PointerToIntegralCast.ql

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@
1515

1616
import cpp
1717
import codingstandards.cpp.misra
18+
import codingstandards.cpp.types.Type
1819

19-
from ReinterpretCast cast, Type targetType, Type sourceType
20+
from ReinterpretCast cast, PointerType sourceType, Type targetType
2021
where
2122
not isExcluded(cast, Conversions2Package::pointerToIntegralCastQuery()) and
2223
sourceType = cast.getExpr().getType().getUnspecifiedType() and
23-
sourceType instanceof PointerType and
2424
targetType = cast.getType() and
2525
targetType.getUnspecifiedType() instanceof IntegralType and
26-
not (
27-
targetType.(UserType).hasGlobalOrStdName("uintptr_t") or
28-
targetType.(UserType).hasGlobalOrStdName("intptr_t")
29-
)
26+
not stripSpecifiers(targetType).(UserType).hasGlobalOrStdName(["uintptr_t", "intptr_t"])
3027
select cast,
31-
"Cast of object pointer type to integral type '" + targetType.toString() +
28+
"Cast of object pointer type to integral type '" + targetType +
3229
"' instead of 'std::uintptr_t' or 'std::intptr_t'."

0 commit comments

Comments
 (0)