Skip to content

Commit 708d126

Browse files
committed
C++: Update documentation on 'cpp/iterator-to-expired-container'.
1 parent 3eddd31 commit 708d126

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cpp/ql/src/Security/CWE/CWE-416/IteratorToExpiredContainer.qhelp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ This is because the temporary container is not bound to a rvalue reference.
3030
</p>
3131
<sample src="IteratorToExpiredContainerExtendedLifetime.cpp" />
3232

33+
<p>
34+
To fix <code>lifetime_of_temp_not_extended</code> consider rewriting the code so that the temporary's lifetime is extended.
35+
In <code>fixed_lifetime_of_temp_not_extended</code> the lifetime of the temporary object has been extended by storing it in an rvalue reference.
36+
</p>
37+
<sample src="IteratorToExpiredContainerExtendedLifetime-fixed.cpp" />
38+
3339
</example>
3440
<references>
3541

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
void fixed_lifetime_of_temp_not_extended() {
2+
auto&& v = get_vector();
3+
for(auto x : log_and_return_argument(v)) {
4+
use(x); // GOOD: The lifetime of the container returned by `get_vector()` has been extended to the lifetime of `v`.
5+
}
6+
}

0 commit comments

Comments
 (0)