Skip to content

Commit 81593ec

Browse files
authored
Merge pull request #16935 from MathiasVP/iterator-to-expired-container-fp-5
C++: Add `cpp/iterator-to-expired-container` FP
2 parents 6359388 + 48edb77 commit 81593ec

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-416/semmle/tests/IteratorToExpiredContainer/IteratorToExpiredContainer.expected

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
| test.cpp:702:27:702:27 | call to operator[] | This object is destroyed at the end of the full-expression. |
44
| test.cpp:727:23:727:23 | call to operator[] | This object is destroyed at the end of the full-expression. |
55
| test.cpp:735:23:735:23 | call to operator[] | This object is destroyed at the end of the full-expression. |
6+
| test.cpp:857:3:857:17 | pointer to ~PlusPlusReturnByValueIterator output argument | This object is destroyed at the end of the full-expression. |

cpp/ql/test/query-tests/Security/CWE/CWE-416/semmle/tests/IteratorToExpiredContainer/test.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -828,3 +828,33 @@ void test6()
828828
}
829829
}
830830
}
831+
832+
struct PlusPlusReturnByValueIterator
833+
{
834+
using value_type = int;
835+
using difference_type = std::ptrdiff_t;
836+
using pointer = int *;
837+
using reference = int &;
838+
using iterator_category = std::forward_iterator_tag;
839+
840+
PlusPlusReturnByValueIterator();
841+
PlusPlusReturnByValueIterator(PlusPlusReturnByValueIterator const &);
842+
843+
PlusPlusReturnByValueIterator operator++();
844+
bool operator==(PlusPlusReturnByValueIterator other) const;
845+
bool operator!=(PlusPlusReturnByValueIterator other) const;
846+
reference operator*() const;
847+
pointer operator->() const;
848+
849+
~PlusPlusReturnByValueIterator();
850+
851+
PlusPlusReturnByValueIterator begin();
852+
};
853+
854+
void test7()
855+
{
856+
PlusPlusReturnByValueIterator it;
857+
it.operator++(); // GOOD [FALSE POSITIVE]
858+
859+
it.begin();
860+
}

0 commit comments

Comments
 (0)