Skip to content

Commit 51ef7bd

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 b0d18ce commit 51ef7bd

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-
fromReinterpretCastcast,TypetargetType,TypesourceType
20+
fromReinterpretCastcast,PointerTypesourceType,TypetargetType
2021
where
2122
notisExcluded(cast, Conversions2Package::pointerToIntegralCastQuery())and
2223
sourceType=cast.getExpr().getType().getUnspecifiedType()and
23-
sourceTypeinstanceofPointerTypeand
2424
targetType=cast.getType()and
2525
targetType.getUnspecifiedType()instanceofIntegralTypeand
26-
not(
27-
targetType.(UserType).hasGlobalOrStdName("uintptr_t")or
28-
targetType.(UserType).hasGlobalOrStdName("intptr_t")
29-
)
26+
notstripSpecifiers(targetType).(UserType).hasGlobalOrStdName(["uintptr_t","intptr_t"])
3027
selectcast,
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)