public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r15-996] libstdc++: Fix -Wstringop-overflow warning coming from std::vector [PR109849]
@ 2024-06-03 19:38 Francois Dumont
  0 siblings, 0 replies; only message in thread
From: Francois Dumont @ 2024-06-03 19:38 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:0426be454448f8cfb9db21f4f669426afb7b57c8

commit r15-996-g0426be454448f8cfb9db21f4f669426afb7b57c8
Author: François Dumont <frs.dumont@gmail.com>
Date:   Sat Jun 1 22:17:19 2024 +0200

    libstdc++: Fix -Wstringop-overflow warning coming from std::vector [PR109849]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/109849
            * include/bits/vector.tcc
            (std::vector<>::_M_range_insert(iterator, _FwdIt, _FwdIt,
            forward_iterator_tag))[__cplusplus < 201103L]: Add __builtin_unreachable
            expression to tell the compiler that the allocated buffer is large enough to
            receive current elements plus the elements of the range to insert.

Diff:
---
 libstdc++-v3/include/bits/vector.tcc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc
index 36b27dce7b9..c500aab9e56 100644
--- a/libstdc++-v3/include/bits/vector.tcc
+++ b/libstdc++-v3/include/bits/vector.tcc
@@ -933,6 +933,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
 		const size_type __len =
 		  _M_check_len(__n, "vector::_M_range_insert");
+#if __cplusplus < 201103LL
+		if (__len < (__n + (__old_start - __old_finish)))
+		  __builtin_unreachable();
+#endif
+
 		pointer __new_start(this->_M_allocate(__len));
 		pointer __new_finish(__new_start);
 		__try

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-06-03 19:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-03 19:38 [gcc r15-996] libstdc++: Fix -Wstringop-overflow warning coming from std::vector [PR109849] Francois Dumont

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).