mirror of https://github.com/WerWolv/ImHex.git
provider: Fixed opening zero sized files
This commit is contained in:
parent
bbeb7289c1
commit
e25d98ef63
|
@ -200,27 +200,32 @@ namespace hex::plugin::builtin::prv {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->m_mapping = CreateFileMapping(this->m_file, nullptr, PAGE_READWRITE, fileSize.HighPart, fileSize.LowPart, nullptr);
|
if (this->m_fileSize > 0) {
|
||||||
if (this->m_mapping == nullptr || this->m_mapping == INVALID_HANDLE_VALUE) {
|
this->m_mapping = CreateFileMapping(this->m_file, nullptr, PAGE_READWRITE, fileSize.HighPart, fileSize.LowPart, nullptr);
|
||||||
return false;
|
if (this->m_mapping == nullptr || this->m_mapping == INVALID_HANDLE_VALUE) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
auto mappingCleanup = SCOPE_GUARD {
|
auto mappingCleanup = SCOPE_GUARD {
|
||||||
this->m_readable = false;
|
this->m_readable = false;
|
||||||
this->m_mapping = nullptr;
|
this->m_mapping = nullptr;
|
||||||
CloseHandle(this->m_mapping);
|
CloseHandle(this->m_mapping);
|
||||||
};
|
};
|
||||||
|
|
||||||
this->m_mappedFile = MapViewOfFile(this->m_mapping, FILE_MAP_ALL_ACCESS, 0, 0, this->m_fileSize);
|
this->m_mappedFile = MapViewOfFile(this->m_mapping, FILE_MAP_ALL_ACCESS, 0, 0, this->m_fileSize);
|
||||||
if (this->m_mappedFile == nullptr) {
|
if (this->m_mappedFile == nullptr) {
|
||||||
this->m_readable = false;
|
this->m_readable = false;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mappingCleanup.release();
|
||||||
|
|
||||||
|
ProjectFile::setFilePath(this->m_path);
|
||||||
|
} else {
|
||||||
|
this->resize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fileCleanup.release();
|
fileCleanup.release();
|
||||||
mappingCleanup.release();
|
|
||||||
|
|
||||||
ProjectFile::setFilePath(this->m_path);
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
this->m_file = ::open(this->m_path.data(), O_RDWR);
|
this->m_file = ::open(this->m_path.data(), O_RDWR);
|
||||||
|
|
Loading…
Reference in New Issue