|
10 | 10 | * statistical |
11 | 11 | * non-attributable |
12 | 12 | */ |
| 13 | + |
13 | 14 | import cpp |
14 | 15 | import semmle.code.cpp.dataflow.EscapesTree |
15 | 16 |
|
16 | 17 | from Function f, Parameter p, Type t, int size |
17 | | -where f.getAParameter() = p |
18 | | - and p.getType() = t |
19 | | - and t.getSize() = size |
20 | | - and size > 64 |
21 | | - and not t.getUnderlyingType() instanceof ArrayType |
22 | | - and not f instanceof CopyAssignmentOperator |
| 18 | +where |
| 19 | + f.getAParameter() = p and |
| 20 | + p.getType() = t and |
| 21 | + t.getSize() = size and |
| 22 | + size > 64 and |
| 23 | + not t.getUnderlyingType() instanceof ArrayType and |
| 24 | + not f instanceof CopyAssignmentOperator and |
23 | 25 | // exception: p is written to, which may mean the copy is intended |
24 | | - and not p.getAnAccess().isAddressOfAccessNonConst() |
25 | | - and not exists(Expr e | |
| 26 | + not p.getAnAccess().isAddressOfAccessNonConst() and |
| 27 | + not exists(Expr e | |
26 | 28 | variableAccessedAsValue(p.getAnAccess(), e.getFullyConverted()) and |
27 | 29 | ( |
28 | | - exists(Assignment an | an.getLValue() = e) or |
29 | | - exists(CrementOperation co | co.getOperand() = e) or |
| 30 | + exists(Assignment an | an.getLValue() = e) |
| 31 | + or |
| 32 | + exists(CrementOperation co | co.getOperand() = e) |
| 33 | + or |
30 | 34 | exists(FunctionCall fc | fc.getQualifier() = e and not fc.getTarget().hasSpecifier("const")) |
31 | 35 | ) |
32 | | - ) |
| 36 | + ) and |
33 | 37 | // if there's no block, we can't tell how the parameter is used |
34 | | - and exists(f.getBlock()) |
35 | | -select |
36 | | - p, "This parameter of type $@ is " + size.toString() + " bytes - consider passing a const pointer/reference instead.", |
37 | | - t, t.toString() |
| 38 | + exists(f.getBlock()) |
| 39 | +select p, |
| 40 | + "This parameter of type $@ is " + size.toString() + |
| 41 | + " bytes - consider passing a const pointer/reference instead.", t, t.toString() |
0 commit comments