From c1baef687bd2e53aa5ac54b825d66eda86c9e408 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 3 Jul 2013 12:22:18 +0000 Subject: [PATCH] Prevent error message when formatting an empty file. This fixes llvm.org/PR16514. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185531 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/clang-format/ClangFormat.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp index 33b7be9f1e..2aa43259ed 100644 --- a/tools/clang-format/ClangFormat.cpp +++ b/tools/clang-format/ClangFormat.cpp @@ -162,6 +162,8 @@ static bool format(std::string FileName) { llvm::errs() << ec.message() << "\n"; return true; } + if (Code->getBufferSize() == 0) + return true; // Empty files are formatted correctly. FileID ID = createInMemoryFile(FileName, Code.get(), Sources, Files); if (Offsets.empty()) Offsets.push_back(0); -- 2.40.0