refactor: Refactor function _glfw_calloc

A simple refactor for the `_glfw_calloc` function. It does not modify the original function behavior, it just makes it more human readable and reduces the indentation.

Also, I created a constant called `total_size`, so the program doesn't need to multiply the same two variables three times.
This commit is contained in:
CiroZDP 2025-12-27 19:07:40 +01:00 committed by GitHub
parent dbadda2683
commit c8d05935d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -248,27 +248,24 @@ int _glfw_max(int a, int b)
void* _glfw_calloc(size_t count, size_t size)
{
if (count && size)
{
void* block;
if (count > SIZE_MAX / size)
{
_glfwInputError(GLFW_INVALID_VALUE, "Allocation size overflow");
return NULL;
}
block = _glfw.allocator.allocate(count * size, _glfw.allocator.user);
if (block)
return memset(block, 0, count * size);
else
{
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
return NULL;
}
}
else
if (!count || !size)
return NULL;
const size_t total_size = count * size;
if (total_size > SIZE_MAX)
{
_glfwInputError(GLFW_INVALID_VALUE, "Allocation size overflow");
return NULL;
}
void* block = _glfw.allocator.allocate(total_size, _glfw.allocator.user);
if (!block)
{
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
return NULL;
}
return memset(block, 0, total_size);
}
void* _glfw_realloc(void* block, size_t size)