Update mju_malloc to return NULL for zero-sized allocations

This commit is contained in:
ashutosh0x
2026-02-13 19:22:05 +05:30
parent c962188655
commit 04e5df08a9
+5 -5
View File
@@ -207,18 +207,18 @@ void* mju_malloc(size_t size) {
// default allocator // default allocator
else { else {
// pad size to multiple of 64 // pad size to multiple of 64
if (size == 0) { if (size > 0 && (size % 64)) {
size = 64;
} else if ((size % 64)) {
size += 64 - (size % 64); size += 64 - (size % 64);
} }
// allocate // allocate
ptr = mju_alignedMalloc(size, 64); if (size > 0) {
ptr = mju_alignedMalloc(size, 64);
}
} }
// error if null pointer // error if null pointer
if (!ptr) { if (!ptr && size > 0) {
mju_error("Could not allocate memory"); mju_error("Could not allocate memory");
} }