summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKEKW555 <152369890+KEKW555@users.noreply.github.com>2023-12-24 10:38:30 +0530
committerGitHub <noreply@github.com>2023-12-23 21:08:30 -0800
commit1e8ced01e6fd0f2a5fa607363dcb3af5eaaf9df3 (patch)
tree7637e158b10df5bbb205951bb7fafee8fa958001
parent50b8efb7d95389c104c1ccb3035790a8ca5df66c (diff)
True match zMalloc (#659)
* True match zMalloc * Cleanup
-rw-r--r--src/common.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/common.c b/src/common.c
index e05db3ee..f4266ce8 100644
--- a/src/common.c
+++ b/src/common.c
@@ -350,9 +350,8 @@ void sub_0801D898(void* dest, void* src, u32 word, u32 size) {
}
void* zMalloc(u32 size) {
-
- FORCE_REGISTER(u32 slotFound, r5);
u16* heapStartOffset;
+ u32 slotFound;
u8* allocatedEntryStartOffset;
u8* allocatedEntryEndOffset;
u8* candidateSlotEndOffset;
@@ -377,7 +376,8 @@ void* zMalloc(u32 size) {
if ((allocatedEntryStartOffset <= candidateSlotStartOffset &&
candidateSlotStartOffset <= allocatedEntryEndOffset)) {
- goto other_search;
+ slotFound = FALSE;
+ break;
}
if ((allocatedEntryStartOffset <= candidateSlotEndOffset &&
@@ -390,17 +390,15 @@ void* zMalloc(u32 size) {
candidateSlotEndOffset <= allocatedEntryEndOffset) ||
(candidateSlotStartOffset <= allocatedEntryStartOffset &&
allocatedEntryEndOffset <= candidateSlotEndOffset)) {
- goto other_search;
+ slotFound = FALSE;
+ break;
}
}
if (!slotFound) {
- other_search:
-
index1 = 0;
// Start searching for candidate slot from the left side of the heap buffer.
do {
-
candidateSlotEndOffset = gzHeap + heapStartOffset[(index1 * 2) + 1];
candidateSlotStartOffset = candidateSlotEndOffset - size;
slotFound = FALSE;
@@ -417,7 +415,8 @@ void* zMalloc(u32 size) {
if ((allocatedEntryStartOffset <= candidateSlotStartOffset &&
candidateSlotStartOffset < allocatedEntryEndOffset)) {
- goto iter_end;
+ slotFound = FALSE;
+ break;
}
if ((allocatedEntryStartOffset < candidateSlotEndOffset &&
@@ -430,17 +429,13 @@ void* zMalloc(u32 size) {
candidateSlotEndOffset <= allocatedEntryEndOffset) ||
(candidateSlotStartOffset <= allocatedEntryStartOffset &&
allocatedEntryEndOffset <= candidateSlotEndOffset)) {
- goto iter_end;
+ slotFound = FALSE;
+ break;
}
}
if (slotFound) {
break;
- } else {
- continue;
}
-
- iter_end:
- slotFound = FALSE;
}
} while ((index1 = (u16)(index1 + 1)) < numEntries);
}