1616import cpp
1717import codingstandards.c.misra
1818import codingstandards.c.Objects
19+ import codingstandards.cpp.Expr
1920
2021/**
2122 * Holds if the value of an expression is used or stored.
@@ -37,32 +38,14 @@ predicate isUsedOrStored(Expr e) {
3738 e = any ( ClassAggregateLiteral l ) .getAFieldExpr ( _)
3839}
3940
40- /**
41- * Find expressions that defer their value directly to an inner expression
42- * value.
43- *
44- * When an array is on the rhs of a comma expr, or in the then/else branch of a
45- * ternary expr, and the result us used as a pointer, then the ArrayToPointer
46- * conversion is marked inside comma expr/ternary expr, on the operands. These
47- * conversions are only non-compliant if they flow into an operation or store.
48- *
49- * Full flow analysis with localFlowStep should not be necessary, and may cast a
50- * wider net than needed for some queries, potentially resulting in false
51- * positives.
52- */
53- Expr temporaryObjectFlowStep ( Expr e ) {
54- e = result .( CommaExpr ) .getRightOperand ( )
55- or
56- e = result .( ConditionalExpr ) .getThen ( )
57- or
58- e = result .( ConditionalExpr ) .getElse ( )
59- }
60-
6141from FieldAccess fa , TemporaryObjectIdentity temporary , ArrayToPointerConversion conversion
6242where
6343 not isExcluded ( conversion , InvalidMemory3Package:: arrayToPointerConversionOfTemporaryObjectQuery ( ) ) and
6444 fa = temporary .getASubobjectAccess ( ) and
6545 conversion .getExpr ( ) = fa and
66- isUsedOrStored ( temporaryObjectFlowStep * ( conversion .getExpr ( ) ) )
46+ exists ( Expr useOrStore |
47+ temporaryObjectFlowStep * ( conversion .getExpr ( ) , useOrStore ) and
48+ isUsedOrStored ( useOrStore )
49+ )
6750select conversion , "Array to pointer conversion of array $@ from temporary object $@." ,
6851 fa .getTarget ( ) , fa .getTarget ( ) .getName ( ) , temporary , temporary .toString ( )
0 commit comments