[libcxx-commits] [PATCH] D88849: [libc++] Make sure __clear_and_shrink() maintains string invariants

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 5 13:18:33 PDT 2020


ldionne created this revision.
Herald added subscribers: libcxx-commits, dexonsmith, jkorous.
Herald added a project: libc++.
Herald added a reviewer: libc++.
ldionne requested review of this revision.

__clear_and_shrink() was added in D41976 <https://reviews.llvm.org/D41976>, and a test was added alongside
it to make sure that the string invariants were maintained. However, it
appears that the test never ran under UBSan before, which would have
highlighted the fact that it doesn't actually maintain the string
invariants.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88849

Files:
  libcxx/include/string


Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -3959,6 +3959,7 @@
         __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
         __set_long_cap(0);
         __set_short_size(0);
+        traits_type::assign(*__get_short_pointer(), value_type());
     }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88849.296282.patch
Type: text/x-patch
Size: 395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201005/356a21c3/attachment.bin>


More information about the libcxx-commits mailing list