Author: Nathan James Date: 2021-01-13T11:36:49Z New Revision: ceb9379a90f5a320d19f5694ef00b4d1164fa7d6
URL: https://github.com/llvm/llvm-project/commit/ceb9379a90f5a320d19f5694ef00b4d1164fa7d6 DIFF: https://github.com/llvm/llvm-project/commit/ceb9379a90f5a320d19f5694ef00b4d1164fa7d6.diff LOG: [ADT] Fix join_impl using the wrong size when calculating total length Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D83305 Added: Modified: llvm/include/llvm/ADT/StringExtras.h Removed: ################################################################################ diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h index 1fea700efe0c..0178539bc402 100644 --- a/llvm/include/llvm/ADT/StringExtras.h +++ b/llvm/include/llvm/ADT/StringExtras.h @@ -384,13 +384,16 @@ inline std::string join_impl(IteratorT Begin, IteratorT End, size_t Len = (std::distance(Begin, End) - 1) * Separator.size(); for (IteratorT I = Begin; I != End; ++I) - Len += (*Begin).size(); + Len += I->size(); S.reserve(Len); + size_t PrevCapacity = S.capacity(); + (void)PrevCapacity; S += (*Begin); while (++Begin != End) { S += Separator; S += (*Begin); } + assert(PrevCapacity == S.capacity() && "String grew during building"); return S; } _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits