Base: avoid const_cast in FileInfo

This commit is contained in:
wmayer
2022-06-04 13:13:36 +02:00
parent 3e9ac4b084
commit dd67d9c890

View File

@@ -181,11 +181,18 @@ std::string FileInfo::getTempFileName(const char* FileName, const char* Path)
buf += "/fileXXXXXX";
}
std::vector<char> 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<char*>(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;