summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-12-02 03:45:18 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2023-12-02 03:58:05 (GMT)
commita820877d033069062f2cac83d9e611d5af905d0a (patch)
treec82f66e8e3ff1d11f5a996c7a0dd51e362588e43 /Source
parent5cf7018af6a5f5f0c84c9b7d5b31d9f849503886 (diff)
downloadCMake-a820877d033069062f2cac83d9e611d5af905d0a.zip
CMake-a820877d033069062f2cac83d9e611d5af905d0a.tar.gz
CMake-a820877d033069062f2cac83d9e611d5af905d0a.tar.bz2
errors: avoid constructing a stream before getting the last error
Constructing a stream may involve operations that change the global error state. Avoid the streams by using `cmStrCat` instead.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCoreTryCompile.cxx12
-rw-r--r--Source/cmExportCommand.cxx12
-rw-r--r--Source/cmFileCommand.cxx11
-rw-r--r--Source/cmFileCopier.cxx7
-rw-r--r--Source/cmake.cxx6
5 files changed, 20 insertions, 28 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 7e19812..8c84ace 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -626,13 +626,11 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
// now create a CMakeLists.txt file in that directory
FILE* fout = cmsys::SystemTools::Fopen(outFileName, "w");
if (!fout) {
- std::ostringstream e;
- /* clang-format off */
- e << "Failed to open\n"
- " " << outFileName << "\n"
- << cmSystemTools::GetLastSystemError();
- /* clang-format on */
- this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmStrCat("Failed to open\n"
+ " ",
+ outFileName, '\n', cmSystemTools::GetLastSystemError()));
return cm::nullopt;
}
diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx
index e78b869..7e44210 100644
--- a/Source/cmExportCommand.cxx
+++ b/Source/cmExportCommand.cxx
@@ -385,13 +385,11 @@ static void StorePackageRegistry(cmMakefile& mf, std::string const& package,
if (entry) {
entry << content << "\n";
} else {
- std::ostringstream e;
- /* clang-format off */
- e << "Cannot create package registry file:\n"
- << " " << fname << "\n"
- << cmSystemTools::GetLastSystemError() << "\n";
- /* clang-format on */
- mf.IssueMessage(MessageType::WARNING, e.str());
+ mf.IssueMessage(MessageType::WARNING,
+ cmStrCat("Cannot create package registry file:\n"
+ " ",
+ fname, '\n',
+ cmSystemTools::GetLastSystemError(), '\n'));
}
}
}
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 93bed9a..c65136c 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -3022,16 +3022,15 @@ bool HandleCreateLinkCommand(std::vector<std::string> const& args,
// Check if the new file already exists and remove it.
if (cmSystemTools::PathExists(newFileName) &&
!cmSystemTools::RemoveFile(newFileName)) {
- std::ostringstream e;
- e << "Failed to create link '" << newFileName
- << "' because existing path cannot be removed: "
- << cmSystemTools::GetLastSystemError() << "\n";
+ auto err = cmStrCat("Failed to create link '", newFileName,
+ "' because existing path cannot be removed: ",
+ cmSystemTools::GetLastSystemError(), '\n');
if (!arguments.Result.empty()) {
- status.GetMakefile().AddDefinition(arguments.Result, e.str());
+ status.GetMakefile().AddDefinition(arguments.Result, err);
return true;
}
- status.SetError(e.str());
+ status.SetError(err);
return false;
}
diff --git a/Source/cmFileCopier.cxx b/Source/cmFileCopier.cxx
index d6e91fa..686162b 100644
--- a/Source/cmFileCopier.cxx
+++ b/Source/cmFileCopier.cxx
@@ -119,10 +119,9 @@ std::string const& cmFileCopier::ToName(std::string const& fromName)
bool cmFileCopier::ReportMissing(const std::string& fromFile)
{
// The input file does not exist and installation is not optional.
- std::ostringstream e;
- e << this->Name << " cannot find \"" << fromFile
- << "\": " << cmSystemTools::GetLastSystemError() << ".";
- this->Status.SetError(e.str());
+ this->Status.SetError(cmStrCat(this->Name, " cannot find \"", fromFile,
+ "\": ", cmSystemTools::GetLastSystemError(),
+ '.'));
return false;
}
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 942c59b..f54196b 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -1707,10 +1707,8 @@ void cmake::SetTraceFile(const std::string& file)
this->TraceFile.close();
this->TraceFile.open(file.c_str());
if (!this->TraceFile) {
- std::stringstream ss;
- ss << "Error opening trace file " << file << ": "
- << cmSystemTools::GetLastSystemError();
- cmSystemTools::Error(ss.str());
+ cmSystemTools::Error(cmStrCat("Error opening trace file ", file, ": ",
+ cmSystemTools::GetLastSystemError()));
return;
}
std::cout << "Trace will be written to " << file << '\n';