]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix -Wstringop-overflow warning coming from std::vector [PR109849]
authorFrançois Dumont <frs.dumont@gmail.com>
Sat, 1 Jun 2024 20:17:19 +0000 (22:17 +0200)
committerFrançois Dumont <frs.dumont@gmail.com>
Mon, 3 Jun 2024 19:34:05 +0000 (21:34 +0200)
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.

libstdc++-v3/include/bits/vector.tcc

index 36b27dce7b99ecc45bb62eb4350efb82eec296c4..c500aab9e561f9e5742bac6732606824ede1d99e 100644 (file)
@@ -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