[clang] 7681435 - [clang-format] Assert that filenames are not empty
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 6 09:25:27 PST 2019
Author: paulhoad
Date: 2019-11-06T17:25:17Z
New Revision: 7681435de148cf7a1c7db1b0daba0497630989d2
URL: https://github.com/llvm/llvm-project/commit/7681435de148cf7a1c7db1b0daba0497630989d2
DIFF: https://github.com/llvm/llvm-project/commit/7681435de148cf7a1c7db1b0daba0497630989d2.diff
LOG: [clang-format] Assert that filenames are not empty
Summary:
Adds asserts to catch empty filenames, which otherwise will cause a crash in SourceManager.
The clang-format tool now outputs an error if an empty filename is used.
Fixes bug: 34667
Reviewers: krasimir, djasper, MyDeveloperDay
Reviewed By: MyDeveloperDay
Subscribers: cfe-commits
Patch by: @jr
Tags: #clang-format, #clang
Differential Revision: https://reviews.llvm.org/D56345
Added:
Modified:
clang/tools/clang-format/ClangFormat.cpp
Removed:
################################################################################
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index db00d41d0351..8a2ec2dde03b 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -390,6 +390,10 @@ static bool format(StringRef FileName) {
if (fillRanges(Code.get(), Ranges))
return true;
StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;
+ if (AssumedFileName.empty()) {
+ llvm::errs() << "error: empty filenames are not allowed\n";
+ return true;
+ }
llvm::Expected<FormatStyle> FormatStyle =
getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer());
More information about the cfe-commits
mailing list