]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: [_GLIBCXX_DEBUG] Fix std::__niter_wrap behavior
authorFrançois Dumont <fdumont@gcc.gnu.org>
Tue, 20 Feb 2024 18:24:47 +0000 (19:24 +0100)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Tue, 20 Feb 2024 21:40:11 +0000 (22:40 +0100)
In _GLIBCXX_DEBUG mode the std::__niter_base can remove 2 layers, the
__gnu_debug::_Safe_iterator<> and the __gnu_cxx::__normal_iterator<>.
When std::__niter_wrap is called to build a __gnu_debug::_Safe_iterator<>
from a __gnu_cxx::__normal_iterator<> we then have a consistency issue
as the difference between the 2 iterators will done on a __normal_iterator
on one side and a C pointer on the other. To avoid this problem call
std::__niter_base on both input iterators.

libstdc++-v3/ChangeLog:

* include/bits/stl_algobase.h (std::__niter_wrap): Add a call to
std::__niter_base on res iterator.

libstdc++-v3/include/bits/stl_algobase.h

index 0f73da131729d2940fa815033168b39048d4c5ae..d534e02871f62f3c58d13c92cfb1d69be0a58d55 100644 (file)
@@ -344,7 +344,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _GLIBCXX20_CONSTEXPR
     inline _From
     __niter_wrap(_From __from, _To __res)
-    { return __from + (__res - std::__niter_base(__from)); }
+    { return __from + (std::__niter_base(__res) - std::__niter_base(__from)); }
 
   // No need to wrap, iterator already has the right type.
   template<typename _Iterator>