mirror of
https://github.com/diamante0018/BlackOpsPlugin.git
synced 2025-04-21 02:35:43 +00:00
refactor(memory): remove nullptr check before std::free
This commit is contained in:
parent
51dc00790b
commit
452cabfa7b
@ -30,7 +30,7 @@ void memory::allocator::free(const void* data) {
|
|||||||
this->free(const_cast<void*>(data));
|
this->free(const_cast<void*>(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void* memory::allocator::allocate(const size_t length) {
|
void* memory::allocator::allocate(const std::size_t length) {
|
||||||
std::lock_guard _(this->mutex_);
|
std::lock_guard _(this->mutex_);
|
||||||
|
|
||||||
const auto data = memory::allocate(length);
|
const auto data = memory::allocate(length);
|
||||||
@ -48,7 +48,9 @@ char* memory::allocator::duplicate_string(const std::string& string) {
|
|||||||
return data;
|
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) {
|
char* memory::duplicate_string(const std::string& string) {
|
||||||
const auto new_string = allocate_array<char>(string.size() + 1);
|
const auto new_string = allocate_array<char>(string.size() + 1);
|
||||||
@ -56,18 +58,14 @@ char* memory::duplicate_string(const std::string& string) {
|
|||||||
return new_string;
|
return new_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
void memory::free(void* data) {
|
void memory::free(void* data) { std::free(data); }
|
||||||
if (data) {
|
|
||||||
::free(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void memory::free(const void* data) { free(const_cast<void*>(data)); }
|
void memory::free(const void* data) { free(const_cast<void*>(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<const char*>(mem);
|
const auto mem_arr = static_cast<const char*>(mem);
|
||||||
|
|
||||||
for (size_t i = 0; i < length; ++i) {
|
for (std::size_t i = 0; i < length; ++i) {
|
||||||
if (mem_arr[i] != chr) {
|
if (mem_arr[i] != chr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -119,9 +117,9 @@ bool memory::is_rdata_ptr(void* pointer) {
|
|||||||
|
|
||||||
if (name == rdata) {
|
if (name == rdata) {
|
||||||
const auto target = size_t(pointer);
|
const auto target = size_t(pointer);
|
||||||
const size_t source_start =
|
const std::size_t source_start =
|
||||||
size_t(pointer_lib.get_ptr()) + section->PointerToRawData;
|
std::size_t(pointer_lib.get_ptr()) + section->PointerToRawData;
|
||||||
const size_t source_end = source_start + section->SizeOfRawData;
|
const std::size_t source_end = source_start + section->SizeOfRawData;
|
||||||
|
|
||||||
return target >= source_start && target <= source_end;
|
return target >= source_start && target <= source_end;
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@ public:
|
|||||||
|
|
||||||
void free(const void* data);
|
void free(const void* data);
|
||||||
|
|
||||||
void* allocate(size_t length);
|
void* allocate(std::size_t length);
|
||||||
|
|
||||||
template <typename T> T* allocate() { return this->allocate_array<T>(1); }
|
template <typename T> T* allocate() { return this->allocate_array<T>(1); }
|
||||||
|
|
||||||
template <typename T> T* allocate_array(const size_t count = 1) {
|
template <typename T> T* allocate_array(const std::size_t count = 1) {
|
||||||
return static_cast<T*>(this->allocate(count * sizeof(T)));
|
return static_cast<T*>(this->allocate(count * sizeof(T)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,11 +33,11 @@ public:
|
|||||||
std::vector<void*> pool_;
|
std::vector<void*> pool_;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void* allocate(size_t length);
|
static void* allocate(std::size_t length);
|
||||||
|
|
||||||
template <typename T> static T* allocate() { return allocate_array<T>(1); }
|
template <typename T> static T* allocate() { return allocate_array<T>(1); }
|
||||||
|
|
||||||
template <typename T> static T* allocate_array(const size_t count = 1) {
|
template <typename T> static T* allocate_array(const std::size_t count = 1) {
|
||||||
return static_cast<T*>(allocate(count * sizeof(T)));
|
return static_cast<T*>(allocate(count * sizeof(T)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ public:
|
|||||||
static void free(void* data);
|
static void free(void* data);
|
||||||
static void free(const 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_read_ptr(const void* ptr);
|
||||||
static bool is_bad_code_ptr(const void* ptr);
|
static bool is_bad_code_ptr(const void* ptr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user