diff --git a/clang-tools-extra/clangd/ClangDMain.cpp b/clang-tools-extra/clangd/ClangDMain.cpp index e851ea77d512..997c66748a0d 100644 --- a/clang-tools-extra/clangd/ClangDMain.cpp +++ b/clang-tools-extra/clangd/ClangDMain.cpp @@ -68,18 +68,17 @@ int main(int argc, char *argv[]) { // Now read the JSON. Insert a trailing null byte as required by the YAML // parser. - std::vector JSON(Len + 1); + std::vector JSON(Len + 1, '\0'); std::cin.read(JSON.data(), Len); if (Len > 0) { + llvm::StringRef JSONRef(JSON.data(), Len); // Log the message. - Logs << "<-- "; - Logs.write(JSON.data(), JSON.size()); - Logs << '\n'; + Logs << "<-- " << JSONRef << '\n'; Logs.flush(); // Finally, execute the action for this JSON message. - if (!Dispatcher.call(llvm::StringRef(JSON.data(), JSON.size() - 1))) + if (!Dispatcher.call(JSONRef)) Logs << "JSON dispatch failed!\n"; } } diff --git a/clang-tools-extra/test/clangd/formatting.test b/clang-tools-extra/test/clangd/formatting.test index 2fa7caef7cdd..b65f35a8dfaf 100644 --- a/clang-tools-extra/test/clangd/formatting.test +++ b/clang-tools-extra/test/clangd/formatting.test @@ -1,5 +1,4 @@ -# RUN: sed -e '/^#/d' %s | clangd | FileCheck %s -# It is absolutely vital that this file has CRLF line endings. +# RUN: sed -e '/^#/d' -e 's/\r*$/\r/' %s | clangd | FileCheck %s # Content-Length: 125