diff --git a/src/common/utils/memory.cpp b/src/common/utils/memory.cpp index 00d4d96..ec7236f 100644 --- a/src/common/utils/memory.cpp +++ b/src/common/utils/memory.cpp @@ -30,7 +30,7 @@ void memory::allocator::free(const void* data) { this->free(const_cast(data)); } -void* memory::allocator::allocate(const size_t length) { +void* memory::allocator::allocate(const std::size_t length) { std::lock_guard _(this->mutex_); const auto data = memory::allocate(length); @@ -48,7 +48,9 @@ char* memory::allocator::duplicate_string(const std::string& string) { return data; } -void* memory::allocate(const size_t length) { return calloc(length, 1); } +void* memory::allocate(const std::size_t length) { + return std::calloc(length, 1); +} char* memory::duplicate_string(const std::string& string) { const auto new_string = allocate_array(string.size() + 1); @@ -56,18 +58,14 @@ char* memory::duplicate_string(const std::string& string) { return new_string; } -void memory::free(void* data) { - if (data) { - ::free(data); - } -} +void memory::free(void* data) { std::free(data); } void memory::free(const void* data) { free(const_cast(data)); } -bool memory::is_set(const void* mem, const char chr, const size_t length) { +bool memory::is_set(const void* mem, const char chr, const std::size_t length) { const auto mem_arr = static_cast(mem); - for (size_t i = 0; i < length; ++i) { + for (std::size_t i = 0; i < length; ++i) { if (mem_arr[i] != chr) { return false; } @@ -119,9 +117,9 @@ bool memory::is_rdata_ptr(void* pointer) { if (name == rdata) { const auto target = size_t(pointer); - const size_t source_start = - size_t(pointer_lib.get_ptr()) + section->PointerToRawData; - const size_t source_end = source_start + section->SizeOfRawData; + const std::size_t source_start = + std::size_t(pointer_lib.get_ptr()) + section->PointerToRawData; + const std::size_t source_end = source_start + section->SizeOfRawData; return target >= source_start && target <= source_end; } diff --git a/src/common/utils/memory.hpp b/src/common/utils/memory.hpp index cacf25f..cc5ba8c 100644 --- a/src/common/utils/memory.hpp +++ b/src/common/utils/memory.hpp @@ -16,11 +16,11 @@ public: void free(const void* data); - void* allocate(size_t length); + void* allocate(std::size_t length); template T* allocate() { return this->allocate_array(1); } - template T* allocate_array(const size_t count = 1) { + template T* allocate_array(const std::size_t count = 1) { return static_cast(this->allocate(count * sizeof(T))); } @@ -33,11 +33,11 @@ public: std::vector pool_; }; - static void* allocate(size_t length); + static void* allocate(std::size_t length); template static T* allocate() { return allocate_array(1); } - template static T* allocate_array(const size_t count = 1) { + template static T* allocate_array(const std::size_t count = 1) { return static_cast(allocate(count * sizeof(T))); } @@ -46,7 +46,7 @@ public: static void free(void* data); static void free(const void* data); - static bool is_set(const void* mem, char chr, size_t length); + static bool is_set(const void* mem, char chr, std::size_t length); static bool is_bad_read_ptr(const void* ptr); static bool is_bad_code_ptr(const void* ptr);