diff --git a/include/views/view_pattern.hpp b/include/views/view_pattern.hpp index d341e28fb..7594b3c96 100644 --- a/include/views/view_pattern.hpp +++ b/include/views/view_pattern.hpp @@ -26,7 +26,7 @@ namespace hex { void createView() override; private: - char *m_buffer; + char *m_buffer = nullptr; std::vector &m_highlights; prv::Provider* &m_dataProvider; diff --git a/source/views/view_pattern.cpp b/source/views/view_pattern.cpp index 73c4f0ccb..15fbcd5e7 100644 --- a/source/views/view_pattern.cpp +++ b/source/views/view_pattern.cpp @@ -7,11 +7,10 @@ namespace hex { ViewPattern::ViewPattern(prv::Provider* &dataProvider, std::vector &highlights) : View(), m_dataProvider(dataProvider), m_highlights(highlights) { - this->m_buffer = new char[0xFFFFFF]; - std::memset(this->m_buffer, 0x00, 0xFFFFFF); } ViewPattern::~ViewPattern() { - delete[] this->m_buffer; + if (this->m_buffer != nullptr) + delete[] this->m_buffer; } void ViewPattern::createMenu() { @@ -66,10 +65,10 @@ namespace hex { size_t size = ftell(file); rewind(file); - if (size > 0xFF'FFFF) { - fclose(file); - return; - } + if (this->m_buffer != nullptr) + delete[] this->m_buffer; + this->m_buffer = new char[size + 1]; + std::memset(this->m_buffer, 0x00, size + 1); fread(this->m_buffer, size, 1, file);