From 331f3eb063ceb772f8a5b5b12da1383614285b45 Mon Sep 17 00:00:00 2001 From: Ottmar Zittlau Date: Sun, 5 Jan 2025 13:14:19 +0100 Subject: [PATCH] Fix unchecked optional access in compile subcommand --- toolchain/driver/compile_subcommand.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/toolchain/driver/compile_subcommand.cpp b/toolchain/driver/compile_subcommand.cpp index 175a0c6313063..f0cb9e47d1e85 100644 --- a/toolchain/driver/compile_subcommand.cpp +++ b/toolchain/driver/compile_subcommand.cpp @@ -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",