Skip to content

Commit 69417e1

Browse files
committed
C++: Address review comments.
1 parent 1bf4305 commit 69417e1

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/MustFlow.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ private module Cached {
177177
operand.getDef() = instr
178178
}
179179

180+
/**
181+
* Holds if data flows from `operand` to `instr`.
182+
*
183+
* This predicate ignores flow through `PhiInstruction`s to create a 'must flow' relation.
184+
*/
180185
private predicate operandToInstructionStep(Operand operand, Instruction instr) {
181186
instr.(CopyInstruction).getSourceValueOperand() = operand
182187
or

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory/ReturnStackAllocatedMemory.expected

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ edges
100100
| test.cpp:190:10:190:13 | Unary | test.cpp:190:10:190:13 | (reference dereference) |
101101
| test.cpp:190:10:190:13 | Unary | test.cpp:190:10:190:13 | (reference to) |
102102
| test.cpp:190:10:190:13 | pRef | test.cpp:190:10:190:13 | Unary |
103+
| test.cpp:225:14:225:15 | px | test.cpp:226:10:226:11 | Load |
104+
| test.cpp:226:10:226:11 | Load | test.cpp:226:10:226:11 | px |
105+
| test.cpp:226:10:226:11 | px | test.cpp:226:10:226:11 | StoreValue |
106+
| test.cpp:231:16:231:17 | & ... | test.cpp:225:14:225:15 | px |
107+
| test.cpp:231:17:231:17 | Unary | test.cpp:231:16:231:17 | & ... |
108+
| test.cpp:231:17:231:17 | x | test.cpp:231:17:231:17 | Unary |
103109
nodes
104110
| test.cpp:17:9:17:11 | & ... | semmle.label | & ... |
105111
| test.cpp:17:9:17:11 | StoreValue | semmle.label | StoreValue |
@@ -215,6 +221,13 @@ nodes
215221
| test.cpp:190:10:190:13 | Unary | semmle.label | Unary |
216222
| test.cpp:190:10:190:13 | Unary | semmle.label | Unary |
217223
| test.cpp:190:10:190:13 | pRef | semmle.label | pRef |
224+
| test.cpp:225:14:225:15 | px | semmle.label | px |
225+
| test.cpp:226:10:226:11 | Load | semmle.label | Load |
226+
| test.cpp:226:10:226:11 | StoreValue | semmle.label | StoreValue |
227+
| test.cpp:226:10:226:11 | px | semmle.label | px |
228+
| test.cpp:231:16:231:17 | & ... | semmle.label | & ... |
229+
| test.cpp:231:17:231:17 | Unary | semmle.label | Unary |
230+
| test.cpp:231:17:231:17 | x | semmle.label | x |
218231
#select
219232
| test.cpp:17:9:17:11 | StoreValue | test.cpp:17:10:17:11 | mc | test.cpp:17:9:17:11 | StoreValue | May return stack-allocated memory from $@. | test.cpp:17:10:17:11 | mc | mc |
220233
| test.cpp:25:9:25:11 | StoreValue | test.cpp:23:18:23:19 | mc | test.cpp:25:9:25:11 | StoreValue | May return stack-allocated memory from $@. | test.cpp:23:18:23:19 | mc | mc |

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ReturnStackAllocatedMemory/test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,13 @@ auto make_read_port()
220220
void* get_sp() {
221221
int p;
222222
return (void*)&p; // GOOD: The function name makes it sound like the programmer intended to get the value of the stack pointer.
223+
}
224+
225+
int* id(int* px) {
226+
return px; // GOOD
227+
}
228+
229+
void f() {
230+
int x;
231+
int* px = id(&x); // GOOD
223232
}

0 commit comments

Comments
 (0)