From fc7f3f4e3df64ac78d820bc2037ebe3fae100d4a Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 4 Jun 2022 13:13:36 +0200 Subject: [PATCH] Base: avoid const_cast in FileInfo --- src/Base/FileInfo.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Base/FileInfo.cpp b/src/Base/FileInfo.cpp index 46a142bb05..b82b851f63 100644 --- a/src/Base/FileInfo.cpp +++ b/src/Base/FileInfo.cpp @@ -181,11 +181,18 @@ std::string FileInfo::getTempFileName(const char* FileName, const char* Path) buf += "/fileXXXXXX"; } + std::vector vec; + std::copy(buf.begin(), buf.end(), std::back_inserter(vec)); + vec.push_back('\0'); + /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */ - int id = mkstemp(const_cast(buf.c_str())); + int id = mkstemp(vec.data()); if (id > -1) { FILE* file = fdopen(id, "w"); fclose(file); + vec.pop_back(); // remove '\0' + std::string str(vec.begin(), vec.end()); + buf.swap(str); unlink(buf.c_str()); } return buf;