diff options
author | Brad King <brad.king@kitware.com> | 2023-01-12 11:04:16 -0500 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-01-12 11:04:16 -0500 |
commit | 2f85ec0a37d1ad75956dd81016a8c7ab90ff845b (patch) | |
tree | 013175e4c246fa8d1097c15ddc091d814b320bcc /Source | |
parent | 6b92224f6c8758e5e84b1425273f4abf3b278f54 (diff) | |
download | cmake-2f85ec0a37d1ad75956dd81016a8c7ab90ff845b.tar.gz |
try_run: Avoid crash in keyword-dispatched signature when cross-compiling
Since commit aa9220d3a0 (try_compile: Add keyword-dispatched signature,
2022-09-02, v3.25.0-rc1~178^2) the `DoNotRunExecutable` code path may be
reached with no single source-file argument. Do not assume it exists.
Fixes: #24295
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmTryRunCommand.cxx | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 1e81195b81..8d62cb1555 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -40,7 +40,7 @@ public: std::string* runOutputStdOutContents, std::string* runOutputStdErrContents); void DoNotRunExecutable(const std::string& runArgs, - const std::string& srcFile, + cm::optional<std::string> const& srcFile, std::string const& compileResultVariable, std::string* runOutputContents, std::string* runOutputStdOutContents, @@ -128,7 +128,7 @@ bool TryRunCommandImpl::TryRunCode(std::vector<std::string> const& argv) if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING") && !this->Makefile->IsDefinitionSet("CMAKE_CROSSCOMPILING_EMULATOR")) { this->DoNotRunExecutable( - runArgs, *arguments.SourceDirectoryOrFile, + runArgs, arguments.SourceDirectoryOrFile, *arguments.CompileResultVariable, captureRunOutput ? &runOutputContents : nullptr, captureRunOutputStdOutErr && arguments.RunOutputStdOutVariable @@ -238,7 +238,7 @@ void TryRunCommandImpl::RunExecutable(const std::string& runArgs, the executable would have produced. */ void TryRunCommandImpl::DoNotRunExecutable( - const std::string& runArgs, const std::string& srcFile, + const std::string& runArgs, cm::optional<std::string> const& srcFile, std::string const& compileResultVariable, std::string* out, std::string* stdOut, std::string* stdErr) { @@ -421,9 +421,11 @@ void TryRunCommandImpl::DoNotRunExecutable( comment += "The "; comment += compileResultVariable; - comment += " variable holds the build result for this try_run().\n\n" - "Source file : "; - comment += srcFile + "\n"; + comment += " variable holds the build result for this try_run().\n\n"; + if (srcFile) { + comment += "Source file : "; + comment += *srcFile + "\n"; + } comment += "Executable : "; comment += copyDest + "\n"; comment += "Run arguments : "; |