mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 21:47:40 -05:00
fix: Crash when trying to read from an empty file or a directory
This commit is contained in:
@@ -57,6 +57,8 @@ namespace hex {
|
||||
if (!isValid()) return {};
|
||||
|
||||
auto size = numBytes ?: getSize();
|
||||
if (size == 0) return {};
|
||||
|
||||
std::vector<u8> bytes(size);
|
||||
auto bytesRead = fread(bytes.data(), 1, bytes.size(), this->m_file);
|
||||
|
||||
@@ -72,6 +74,9 @@ namespace hex {
|
||||
|
||||
auto bytes = readBytes(numBytes);
|
||||
|
||||
if (bytes.empty())
|
||||
return "";
|
||||
|
||||
return { reinterpret_cast<char *>(bytes.data()), bytes.size() };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user