From 9158d791266dce182b57529fc6e578a88a9f0f80 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 27 Nov 2021 14:02:14 +0100 Subject: [PATCH] patterns: Don't display strings with zero length. Fixes crash --- .../include/hex/pattern_language/pattern_data.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp index 94182db76..b10fe02f0 100644 --- a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp +++ b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp @@ -37,7 +37,7 @@ namespace hex::pl { result += static_cast(*c); } - if (*(data + size - 1) == '\x00') + if (size != 0 && *(data + size - 1) == '\x00') result.pop_back(); return result; @@ -638,6 +638,10 @@ namespace hex::pl { void createEntry(prv::Provider* &provider) override { auto size = std::min(this->getSize(), 0x7F); + + if (size == 0) + return; + std::string buffer(size, 0x00); provider->read(this->getOffset(), buffer.data(), size); @@ -679,6 +683,9 @@ namespace hex::pl { void createEntry(prv::Provider* &provider) override { auto size = std::min(this->getSize(), 0x100); + if (size == 0) + return; + std::u16string buffer(this->getSize()/sizeof(char16_t), 0x00); provider->read(this->getOffset(), buffer.data(), size);