]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix bogus -Wstringop-overflow in std::vector::insert [PR117983]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 28 Mar 2025 22:00:38 +0000 (22:00 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 2 Apr 2025 08:55:45 +0000 (09:55 +0100)
commit4366711d2d66ea9a2d4fe9dd112795ef0c6f785c
treefdc3bc1161226ed1d02d360eb3450bf7e829a052
parent6b11aed73f6601de32082a4519022d4de1ce8a8f
libstdc++: Fix bogus -Wstringop-overflow in std::vector::insert [PR117983]

This was fixed on trunk by r15-4473-g3abe751ea86e34, but that isn't
suitable for backporting. Instead, just add another unreachable
condition in std::vector::_M_range_insert so the compiler knows this
memcpy doesn't use a length originating from a negative ptrdiff_t
converted to a very positive size_t.

libstdc++-v3/ChangeLog:

PR libstdc++/117983
* include/bits/vector.tcc (vector::_M_range_insert): Add
unreachable condition to tell the compiler begin() <= end().
* testsuite/23_containers/vector/modifiers/insert/117983.cc: New
test.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
(cherry picked from commit 878812b6f6905774ab37cb78903e3e11bf1c508c)
libstdc++-v3/include/bits/vector.tcc
libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/117983.cc [new file with mode: 0644]