aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Dumont <frs.dumont@gmail.com>2024-06-01 22:17:19 +0200
committerFrançois Dumont <frs.dumont@gmail.com>2024-06-03 21:52:58 +0200
commit955202eb2cdbe2bc74c626bce90ee1eac410ad4f (patch)
tree57ef2ee335b5b5557e8fc5cc71972a05167f641e
parent97474ba2075dc3c397bbc2861646561dcfd13386 (diff)
downloadgcc-955202eb2cdbe2bc74c626bce90ee1eac410ad4f.zip
gcc-955202eb2cdbe2bc74c626bce90ee1eac410ad4f.tar.gz
gcc-955202eb2cdbe2bc74c626bce90ee1eac410ad4f.tar.bz2
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. (cherry picked from commit 0426be454448f8cfb9db21f4f669426afb7b57c8)
-rw-r--r--libstdc++-v3/include/bits/vector.tcc5
1 files changed, 5 insertions, 0 deletions
diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc
index 25df060..42352aa 100644
--- a/libstdc++-v3/include/bits/vector.tcc
+++ b/libstdc++-v3/include/bits/vector.tcc
@@ -1005,6 +1005,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