An der Stelle würde ich statt new[] und delete[] einen unique_ptr benutzen. Ansonten würde der Speicher nicht freigegeben, falls assign eine Exception wirft. Das if(data) ist auch nicht notwendig, da new nie nullptrzurück gibt.
char* data = new char[size];
if (data) {
if (PHYSFS_readBytes(file, data, filesize) == filesize) {
result.assign(data, size);
}
delete[] data;
}
auto data = std::make_unique<char[]>(size);
// oder: std::unique_ptr<char[]> data = std::make_unique<char[]>(size);
if (PHYSFS_readBytes(file, data.get(), filesize) == filesize) {
result.assign(data.get(), size);
}
An der Stelle würde ich statt new[] und delete[] einen unique_ptr benutzen. Ansonten würde der Speicher nicht freigegeben, falls assign eine Exception wirft. Das
if(data)
ist auch nicht notwendig, danew
nienullptr
zurück gibt.https://github.com/ennorehling/csmapfx/blob/master/fxhelper.cpp#L145
Neu: