mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 13:31:06 +01:00
Fix unchecked optional access in compile subcommand (#4756)
Hi, I fixed a small issue that I found inside the "compile subcommand" component: The program can be crashed by running ```bazel run -- toolchain:carbon compile --dump-mem-usage "non-existing-file.carbon"``` - i.e. by activating the memory usage dump flag and passing a non-existing file. Best regards, oz
This commit is contained in:
@@ -369,14 +369,17 @@ class CompilationUnit {
|
||||
source_ = SourceBuffer::MakeFromFileOrStdin(*driver_env_->fs,
|
||||
input_filename_, *consumer_);
|
||||
});
|
||||
if (mem_usage_) {
|
||||
mem_usage_->Add("source_", source_->text().size(),
|
||||
source_->text().size());
|
||||
}
|
||||
|
||||
if (!source_) {
|
||||
success_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mem_usage_) {
|
||||
mem_usage_->Add("source_", source_->text().size(),
|
||||
source_->text().size());
|
||||
}
|
||||
|
||||
CARBON_VLOG("*** SourceBuffer ***\n```\n{0}\n```\n", source_->text());
|
||||
|
||||
LogCall("Lex::Lex", "lex",
|
||||
|
||||
Reference in New Issue
Block a user