Skip to content

Commit 1797b6c

Browse files
committed
C++: Add FP test from the work on smart pointers in dataflow.
1 parent d4fdd50 commit 1797b6c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-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:171:3:171:24 | return ... | May return stack-allocated memory from $@. | test.cpp:170:35:170:41 | myLocal | myLocal |
9+
| test.cpp:217:3:217:13 | return ... | May return stack-allocated memory from $@. | test.cpp:216:14:216:17 | port | port |

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,30 @@ int *&conversionInFlow() {
189189
int *&pRef = p; // has conversion in the middle of data flow
190190
return pRef; // BAD [NOT DETECTED]
191191
}
192+
193+
namespace std {
194+
template<typename T>
195+
class shared_ptr {
196+
public:
197+
shared_ptr() noexcept;
198+
explicit shared_ptr(T*);
199+
shared_ptr(const shared_ptr&) noexcept;
200+
template<class U> shared_ptr(const shared_ptr<U>&) noexcept;
201+
template<class U> shared_ptr(shared_ptr<U>&&) noexcept;
202+
203+
shared_ptr<T>& operator=(const shared_ptr<T>&) noexcept;
204+
shared_ptr<T>& operator=(shared_ptr<T>&&) noexcept;
205+
206+
T& operator*() const noexcept;
207+
T* operator->() const noexcept;
208+
209+
T* get() const noexcept;
210+
};
211+
}
212+
213+
auto make_read_port()
214+
{
215+
auto port = std::shared_ptr<int>(new int);
216+
auto ptr = port.get();
217+
return ptr; // GOOD [FALSE POSITIVE]
218+
}

0 commit comments

Comments
 (0)