Skip to content

Commit 7681435

Browse files
[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
1 parent 1b986b4 commit 7681435

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

clang/tools/clang-format/ClangFormat.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ static bool format(StringRef FileName) {
390390
if (fillRanges(Code.get(), Ranges))
391391
return true;
392392
StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName;
393+
if (AssumedFileName.empty()) {
394+
llvm::errs() << "error: empty filenames are not allowed\n";
395+
return true;
396+
}
393397

394398
llvm::Expected<FormatStyle> FormatStyle =
395399
getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer());

0 commit comments

Comments
 (0)