[PATCH] D83305: [ADT] Fix join_impl using the wrong size when calculating total length
Nathan James via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 12 15:57:23 PST 2021
njames93 updated this revision to Diff 316264.
njames93 added a comment.
Add assert to enusre correct behaviour.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D83305/new/
https://reviews.llvm.org/D83305
Files:
llvm/include/llvm/ADT/StringExtras.h
Index: llvm/include/llvm/ADT/StringExtras.h
===================================================================
--- llvm/include/llvm/ADT/StringExtras.h
+++ llvm/include/llvm/ADT/StringExtras.h
@@ -384,13 +384,16 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83305.316264.patch
Type: text/x-patch
Size: 647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210112/e1ddb568/attachment.bin>
More information about the llvm-commits
mailing list