Skip to content

Commit 31a5a7a

Browse files
authored
Merge pull request #16913 from MathiasVP/add-iterator-to-expired-container-fp-3
C++: Add `cpp/iterator-to-expired-container` FP test
2 parents b7a67b1 + aad233b commit 31a5a7a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
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:826:25:826:43 | pointer to ~HasBeginAndEnd 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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,4 +801,30 @@ void test5(int i)
801801
for(const auto& vs : vvs) { }
802802
++i;
803803
} // GOOD
804-
}
804+
}
805+
806+
struct HasBeginAndEnd
807+
{
808+
~HasBeginAndEnd();
809+
using value_type = int;
810+
using difference_type = std::ptrdiff_t;
811+
using pointer = int*;
812+
using reference = int&;
813+
using iterator_category = std::random_access_iterator_tag;
814+
std::vector<int>::iterator begin() const;
815+
std::vector<int>::iterator end() const;
816+
};
817+
818+
HasBeginAndEnd getHasBeginAndEnd();
819+
820+
bool getBool();
821+
822+
void test6()
823+
{
824+
while(getBool())
825+
{
826+
for (const int& x : getHasBeginAndEnd()) // GOOD [FALSE POSITIVE]
827+
{
828+
}
829+
}
830+
}

0 commit comments

Comments
 (0)