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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits