|
12 | 12 |
|
13 | 13 | import cpp
|
14 | 14 |
|
15 |
| -/** |
16 |
| - * The function allows `getASuccessor` to be called recursively. |
17 |
| - * This provides a stop in situations of possible influence on the pointer. |
18 |
| - */ |
19 |
| -ControlFlowNode recursASuccessor(FunctionCall fc, LocalScopeVariable v) { |
20 |
| - result = fc |
21 |
| - or |
22 |
| - exists(ControlFlowNode mid | |
23 |
| - mid = recursASuccessor(fc, v) and |
24 |
| - result = mid.getASuccessor() and |
25 |
| - not result = v.getAnAssignedValue() and |
26 |
| - not result.(AddressOfExpr).getOperand() = v.getAnAccess() and |
27 |
| - not ( |
28 |
| - not result instanceof DeallocationExpr and |
29 |
| - result.(FunctionCall).getAnArgument().(VariableAccess).getTarget() = v |
30 |
| - ) and |
| 15 | +from FunctionCall fc, FunctionCall fc2, LocalScopeVariable v |
| 16 | +where |
| 17 | + freeCall(fc, v.getAnAccess()) and |
| 18 | + freeCall(fc2, v.getAnAccess()) and |
| 19 | + fc != fc2 and |
| 20 | + fc.getASuccessor*() = fc2 and |
| 21 | + not exists(Expr exptmp | |
| 22 | + (exptmp = v.getAnAssignedValue() or exptmp.(AddressOfExpr).getOperand() = v.getAnAccess()) and |
| 23 | + exptmp = fc.getASuccessor*() and |
| 24 | + exptmp = fc2.getAPredecessor*() |
| 25 | + ) and |
| 26 | + not exists(FunctionCall fctmp | |
| 27 | + not fctmp instanceof DeallocationExpr and |
| 28 | + fctmp = fc.getASuccessor*() and |
| 29 | + fctmp = fc2.getAPredecessor*() and |
| 30 | + fctmp.getAnArgument().(VariableAccess).getTarget() = v |
| 31 | + ) and |
| 32 | + ( |
| 33 | + fc.getTarget().hasGlobalOrStdName("realloc") and |
31 | 34 | (
|
32 |
| - fc.getTarget().hasGlobalOrStdName("realloc") and |
33 |
| - ( |
34 |
| - not fc.getParent*() instanceof IfStmt and |
35 |
| - not result instanceof IfStmt |
| 35 | + not fc.getParent*() instanceof IfStmt and |
| 36 | + not exists(IfStmt iftmp | |
| 37 | + iftmp.getCondition().getAChild*().(VariableAccess).getTarget().getAnAssignedValue() = fc |
36 | 38 | )
|
37 |
| - or |
38 |
| - not fc.getTarget().hasGlobalOrStdName("realloc") |
39 | 39 | )
|
| 40 | + or |
| 41 | + not fc.getTarget().hasGlobalOrStdName("realloc") |
40 | 42 | )
|
41 |
| -} |
42 |
| - |
43 |
| -from FunctionCall fc |
44 |
| -where |
45 |
| - exists(FunctionCall fc2, LocalScopeVariable v | |
46 |
| - freeCall(fc, v.getAnAccess()) and |
47 |
| - freeCall(fc2, v.getAnAccess()) and |
48 |
| - fc != fc2 and |
49 |
| - recursASuccessor(fc, v) = fc2 |
50 |
| - ) |
51 |
| -select fc.getArgument(0), "This pointer may be cleared again later." |
| 43 | +select fc2.getArgument(0), |
| 44 | + "This pointer may have already been cleared in the line " + fc.getLocation().getStartLine() + "." |
0 commit comments