[clang-tools-extra] 3346cec - [clangd] Fix write past end pointer
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 19 12:50:47 PST 2019
Author: Kadir Cetinkaya
Date: 2019-12-19T21:50:32+01:00
New Revision: 3346cecd4c0c960377b441606b6382a684daf061
URL: https://github.com/llvm/llvm-project/commit/3346cecd4c0c960377b441606b6382a684daf061
DIFF: https://github.com/llvm/llvm-project/commit/3346cecd4c0c960377b441606b6382a684daf061.diff
LOG: [clangd] Fix write past end pointer
Added:
Modified:
clang-tools-extra/clangd/FormattedString.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/FormattedString.cpp b/clang-tools-extra/clangd/FormattedString.cpp
index 5c225139de23..a7a63a476c3c 100644
--- a/clang-tools-extra/clangd/FormattedString.cpp
+++ b/clang-tools-extra/clangd/FormattedString.cpp
@@ -104,13 +104,12 @@ std::string canonicalizeSpaces(std::string Input) {
return "";
// Go over each word and add it to the string.
for (llvm::StringRef Word : Words) {
+ if (WritePtr > Input.begin())
+ *WritePtr++ = ' '; // Separate from previous block.
llvm::for_each(Word, [&WritePtr](const char C) { *WritePtr++ = C; });
- // Separate from next block.
- *WritePtr++ = ' ';
}
- // Get rid of extra spaces, -1 is for the trailing space introduced with last
- // word.
- Input.resize(WritePtr - Input.begin() - 1);
+ // Get rid of extra spaces.
+ Input.resize(WritePtr - Input.begin());
return Input;
}
More information about the cfe-commits
mailing list