diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2024-02-23 18:51:14 +0100 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2024-03-07 16:06:10 +0100 |
commit | c512ae174920ada425e2b33d0fea24891d6305bd (patch) | |
tree | ef34d87ce8e4c94a25b5e44b7d53a625ed346076 /src | |
parent | bbeef185dc79a335c983fdd3b503ae10e590458e (diff) | |
download | justbuild-c512ae174920ada425e2b33d0fea24891d6305bd.tar.gz |
just-mr: Fix unguarded optional access
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/git_operations/git_repo_remote.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/other_tools/git_operations/git_repo_remote.cpp b/src/other_tools/git_operations/git_repo_remote.cpp index ac4bc41c..2a434928 100644 --- a/src/other_tools/git_operations/git_repo_remote.cpp +++ b/src/other_tools/git_operations/git_repo_remote.cpp @@ -457,6 +457,13 @@ auto GitRepoRemote::UpdateCommitViaTmpRepo( env, GetGitPath(), // which path is not actually relevant tmp_dir); + + if (not command_output) { + (*logger)(fmt::format("exec() on command failed."), + /*fatal=*/true); + return std::nullopt; + } + // output file can be read anyway std::string out_str{}; auto cmd_out = FileSystemManager::ReadFile(command_output->stdout_file); @@ -464,7 +471,7 @@ auto GitRepoRemote::UpdateCommitViaTmpRepo( out_str = *cmd_out; } // check for command failure - if (not command_output) { + if (command_output->return_value != 0) { std::string err_str{}; auto cmd_err = FileSystemManager::ReadFile(command_output->stderr_file); @@ -600,7 +607,14 @@ auto GitRepoRemote::FetchViaTmpRepo(std::filesystem::path const& tmp_dir, SystemCommand system{repo_url}; auto const command_output = system.Execute(cmdline, env, GetGitPath(), tmp_dir); + if (not command_output) { + (*logger)(fmt::format("exec() on command failed."), + /*fatal=*/true); + return false; + } + + if (command_output->return_value != 0) { std::string out_str{}; std::string err_str{}; auto cmd_out = |