From 7f69f8bcdb218e03053e2568a52096583c40d33e Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 7 Dec 2023 13:02:12 +0100 Subject: [PATCH] impr: More size_t -> u64 --- lib/libimhex/include/hex/helpers/binary_pattern.hpp | 2 +- lib/libimhex/include/hex/providers/provider.hpp | 2 +- lib/libimhex/source/helpers/magic.cpp | 4 ++-- lib/libimhex/source/providers/provider.cpp | 4 ++-- .../builtin/source/content/providers/disk_provider.cpp | 8 ++++---- plugins/builtin/source/content/providers/gdb_provider.cpp | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/libimhex/include/hex/helpers/binary_pattern.hpp b/lib/libimhex/include/hex/helpers/binary_pattern.hpp index b648f36d7..cf1570d0a 100644 --- a/lib/libimhex/include/hex/helpers/binary_pattern.hpp +++ b/lib/libimhex/include/hex/helpers/binary_pattern.hpp @@ -37,7 +37,7 @@ namespace hex { return (byte & pattern.mask) == pattern.value; } - [[nodiscard]] size_t getSize() const { + [[nodiscard]] u64 getSize() const { return this->m_patterns.size(); } diff --git a/lib/libimhex/include/hex/providers/provider.hpp b/lib/libimhex/include/hex/providers/provider.hpp index a85e60923..069970fcf 100644 --- a/lib/libimhex/include/hex/providers/provider.hpp +++ b/lib/libimhex/include/hex/providers/provider.hpp @@ -182,7 +182,7 @@ namespace hex::prv { virtual void setBaseAddress(u64 address); [[nodiscard]] virtual u64 getBaseAddress() const; [[nodiscard]] virtual u64 getCurrentPageAddress() const; - [[nodiscard]] virtual size_t getSize() const; + [[nodiscard]] virtual u64 getSize() const; [[nodiscard]] virtual std::optional getPageOfAddress(u64 address) const; [[nodiscard]] virtual std::vector getDataDescription() const; diff --git a/lib/libimhex/source/helpers/magic.cpp b/lib/libimhex/source/helpers/magic.cpp index 201646910..e2da124ad 100644 --- a/lib/libimhex/source/helpers/magic.cpp +++ b/lib/libimhex/source/helpers/magic.cpp @@ -112,7 +112,7 @@ namespace hex::magic { } std::string getDescription(prv::Provider *provider, size_t size) { - std::vector buffer(std::min(provider->getSize(), size), 0x00); + std::vector buffer(std::min(provider->getSize(), size), 0x00); provider->read(provider->getBaseAddress(), buffer.data(), buffer.size()); return getDescription(buffer); @@ -135,7 +135,7 @@ namespace hex::magic { } std::string getMIMEType(prv::Provider *provider, size_t size) { - std::vector buffer(std::min(provider->getSize(), size), 0x00); + std::vector buffer(std::min(provider->getSize(), size), 0x00); provider->read(provider->getBaseAddress(), buffer.data(), buffer.size()); return getMIMEType(buffer); diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index ff02eb659..fc9d0ea89 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -160,8 +160,8 @@ namespace hex::prv { return this->getPageSize() * this->getCurrentPage(); } - size_t Provider::getSize() const { - return std::min(this->getActualSize() - this->getPageSize() * this->m_currPage, this->getPageSize()); + u64 Provider::getSize() const { + return std::min(this->getActualSize() - this->getPageSize() * this->m_currPage, this->getPageSize()); } std::optional Provider::getPageOfAddress(u64 address) const { diff --git a/plugins/builtin/source/content/providers/disk_provider.cpp b/plugins/builtin/source/content/providers/disk_provider.cpp index 8a3a66c3e..be7203220 100644 --- a/plugins/builtin/source/content/providers/disk_provider.cpp +++ b/plugins/builtin/source/content/providers/disk_provider.cpp @@ -250,7 +250,7 @@ namespace hex::plugin::builtin { this->m_sectorBufferAddress = seekPosition.QuadPart; } - std::memcpy(static_cast(buffer) + (offset - startOffset), this->m_sectorBuffer.data() + (offset & (this->m_sectorSize - 1)), std::min(this->m_sectorSize, size)); + std::memcpy(static_cast(buffer) + (offset - startOffset), this->m_sectorBuffer.data() + (offset & (this->m_sectorSize - 1)), std::min(this->m_sectorSize, size)); size = std::max(static_cast(size) - this->m_sectorSize, 0); offset += this->m_sectorSize; @@ -273,7 +273,7 @@ namespace hex::plugin::builtin { std::memcpy(reinterpret_cast(buffer) + (offset - startOffset), this->m_sectorBuffer.data() + (offset & (this->m_sectorSize - 1)), - std::min(this->m_sectorSize, size)); + std::min(this->m_sectorSize, size)); size = std::max(static_cast(size) - this->m_sectorSize, 0); offset += this->m_sectorSize; @@ -294,7 +294,7 @@ namespace hex::plugin::builtin { while (size > 0) { u64 sectorBase = offset - (offset % this->m_sectorSize); - size_t currSize = std::min(size, this->m_sectorSize); + size_t currSize = std::min(size, this->m_sectorSize); this->readRaw(sectorBase, modifiedSectorBuffer.data(), modifiedSectorBuffer.size()); std::memcpy(modifiedSectorBuffer.data() + ((offset - sectorBase) % this->m_sectorSize), reinterpret_cast(buffer) + (startOffset - offset), currSize); @@ -319,7 +319,7 @@ namespace hex::plugin::builtin { while (size > 0) { u64 sectorBase = offset - (offset % this->m_sectorSize); - size_t currSize = std::min(size, this->m_sectorSize); + size_t currSize = std::min(size, this->m_sectorSize); this->readRaw(sectorBase, modifiedSectorBuffer.data(), modifiedSectorBuffer.size()); std::memcpy(modifiedSectorBuffer.data() + ((offset - sectorBase) % this->m_sectorSize), reinterpret_cast(buffer) + (startOffset - offset), currSize); diff --git a/plugins/builtin/source/content/providers/gdb_provider.cpp b/plugins/builtin/source/content/providers/gdb_provider.cpp index 909616870..bfbb495e4 100644 --- a/plugins/builtin/source/content/providers/gdb_provider.cpp +++ b/plugins/builtin/source/content/providers/gdb_provider.cpp @@ -171,10 +171,10 @@ namespace hex::plugin::builtin { } if (cacheLine != this->m_cache.end()) - std::memcpy(buffer, &cacheLine->data[0] + (offset % CacheLineSize), std::min(size, cacheLine->data.size())); + std::memcpy(buffer, &cacheLine->data[0] + (offset % CacheLineSize), std::min(size, cacheLine->data.size())); } else { while (size > 0) { - size_t readSize = std::min(size, CacheLineSize); + size_t readSize = std::min(size, CacheLineSize); auto data = gdb::readMemory(this->m_socket, offset, size); if (!data.empty())