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;