summaryrefslogtreecommitdiffstats
path: root/Source/cmFileCommand.cxx
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/cmFileCommand.cxx
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/cmFileCommand.cxx')
-rw-r--r--Source/cmFileCommand.cxx11
1 files changed, 5 insertions, 6 deletions
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;
}