[libcxx-commits] [PATCH] D101675: [libc++] [LIBCXX-DEBUG-FIXME] Fix an iterator-invalidation issue in string::assign.
Arthur O'Dwyer via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Apr 30 16:53:26 PDT 2021
Quuxplusone created this revision.
Quuxplusone added reviewers: ldionne, krisb, libc++.
Quuxplusone added a project: libc++.
Quuxplusone requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.
This appears to be a bug in our string::assign: when assigning into
a longer string, from a shorter snippet of itself, we invalidate
iterators before doing the copy. We should invalidate them afterward.
Also drive-by improve the formatting of a function header.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D101675
Files:
libcxx/include/string
libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
Index: libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
===================================================================
--- libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
+++ libcxx/test/std/strings/basic.string/string.modifiers/string_assign/iterator.pass.cpp
@@ -6,8 +6,6 @@
//
//===----------------------------------------------------------------------===//
-// XFAIL: LIBCXX-DEBUG-FIXME
-
// <string>
// template<class InputIterator>
Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -1763,11 +1763,7 @@
template <class _CharT, class _Traits, class _Allocator>
inline
void
-basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
-#if _LIBCPP_DEBUG_LEVEL == 2
- __pos
-#endif
- )
+basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
{
#if _LIBCPP_DEBUG_LEVEL == 2
__c_node* __c = __get_db()->__find_c_and_lock(this);
@@ -1787,6 +1783,8 @@
}
__get_db()->unlock();
}
+#else
+ (void)__pos;
#endif // _LIBCPP_DEBUG_LEVEL == 2
}
@@ -2361,12 +2359,11 @@
size_type __sz = size();
__grow_by(__cap, __n - __cap, __sz, 0, __sz);
}
- else
- __invalidate_iterators_past(__n);
value_type* __p = _VSTD::__to_address(__get_pointer());
traits_type::assign(__p, __n, __c);
traits_type::assign(__p[__n], value_type());
__set_size(__n);
+ __invalidate_iterators_past(__n);
return *this;
}
@@ -2498,13 +2495,12 @@
size_type __sz = size();
__grow_by(__cap, __n - __cap, __sz, 0, __sz);
}
- else
- __invalidate_iterators_past(__n);
pointer __p = __get_pointer();
for (; __first != __last; ++__first, ++__p)
traits_type::assign(*__p, *__first);
traits_type::assign(*__p, value_type());
__set_size(__n);
+ __invalidate_iterators_past(__n);
}
else
{
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101675.342086.patch
Type: text/x-patch
Size: 2248 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210430/931ac083/attachment.bin>
More information about the libcxx-commits
mailing list