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:
ottmar-zittlau
2025-01-08 00:04:16 +00:00
committed by GitHub
parent 13c121c56c
commit 7ed3b986b9
2 changed files with 18 additions and 4 deletions
+7 -4
View File
@@ -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",