[clangd] Fix write past end pointer

This commit is contained in:
Kadir Cetinkaya 2019-12-19 21:50:32 +01:00
parent bc7595d934
commit 3346cecd4c
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
1 changed files with 4 additions and 5 deletions

View File

@ -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;
}