[libcxx-commits] [PATCH] D148693: [libc++] Set correct size at the end of growing std::string
Tacet via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Apr 19 01:56:55 PDT 2023
AdvenamTacet created this revision.
AdvenamTacet added a reviewer: ldionne.
Herald added a project: All.
AdvenamTacet requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
This revision adds setting a correct size at the end of `__grow_by`.
Without it, the function may not keep strings invariants.
Size may be incorrect after growing a string from short (SSO) to long, as place where size is kept could be changed.
This causes problems in D132769 <https://reviews.llvm.org/D132769> and originally was addressed there.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D148693
Files:
libcxx/include/string
Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -2286,6 +2286,7 @@
__alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1);
__set_long_pointer(__p);
__set_long_cap(__allocation.count);
+ __set_long_size(__old_sz);
}
// assign
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148693.514865.patch
Type: text/x-patch
Size: 362 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230419/c572de1a/attachment.bin>
More information about the libcxx-commits
mailing list