fix: Crash when trying to read from an empty file or a directory

This commit is contained in:
WerWolv
2022-02-26 16:43:38 +01:00
parent f3f1ac939a
commit 191a99f91b
2 changed files with 10 additions and 2 deletions

View File

@@ -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() };
}