[llvm-branch-commits] [llvm] ceb9379 - [ADT] Fix join_impl using the wrong size when calculating total length
Nathan James via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jan 13 03:41:00 PST 2021
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;
}
More information about the llvm-branch-commits
mailing list