Skip to content

Commit d864df5

Browse files
committed
C++: Tests for new false negatives
1 parent 6b1cd17 commit d864df5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
| test.cpp:112:2:112:12 | return ... | May return stack-allocated memory from $@. | test.cpp:112:9:112:11 | arr | arr |
77
| test.cpp:119:2:119:19 | return ... | May return stack-allocated memory from $@. | test.cpp:119:11:119:13 | arr | arr |
88
| test.cpp:149:3:149:22 | return ... | May return stack-allocated memory from $@. | test.cpp:149:11:149:21 | threadLocal | threadLocal |
9+
| test.cpp:190:3:190:14 | return ... | May return stack-allocated memory from $@. | test.cpp:188:13:188:19 | myLocal | myLocal |

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,28 @@ char *returnAfterCopy() {
164164
memcpy(staticBuf, localBuf, sizeof(staticBuf));
165165
return staticBuf; // GOOD
166166
}
167+
168+
void *conversionBeforeDataFlow() {
169+
int myLocal;
170+
void *pointerToLocal = (void *)&myLocal; // has conversion
171+
return pointerToLocal; // BAD [NOT DETECTED]
172+
}
173+
174+
void *arrayConversionBeforeDataFlow() {
175+
int localArray[4];
176+
int *pointerToLocal = localArray; // has conversion
177+
return pointerToLocal; // BAD [NOT DETECTED]
178+
}
179+
180+
int &dataFlowThroughReference() {
181+
int myLocal;
182+
int &refToLocal = myLocal; // has conversion
183+
return refToLocal; // BAD [NOT DETECTED]
184+
}
185+
186+
int *&conversionInFlow() {
187+
int myLocal;
188+
int *p = &myLocal;
189+
int *&pRef = p; // has conversion in the middle of data flow
190+
return pRef; // BAD [MISLEADING ALERT MESSAGE]
191+
}

0 commit comments

Comments
 (0)