Reorganize variables scope for goto

Fixes AppleClang complaints.

See #17
This commit is contained in:
Alexander Batalov 2022-05-29 00:32:50 +03:00
parent 86c0585efc
commit 6929e054a9
3 changed files with 29 additions and 13 deletions

View File

@ -227,6 +227,11 @@ bool heapHandleListInit(Heap* heap)
// 0x452AD0 // 0x452AD0
bool heapBlockAllocate(Heap* heap, int* handleIndexPtr, int size, int a4) bool heapBlockAllocate(Heap* heap, int* handleIndexPtr, int size, int a4)
{ {
HeapBlockHeader* blockHeader;
int state;
int blockSize;
HeapHandle* handle;
if (heap == NULL || handleIndexPtr == NULL || size == 0) { if (heap == NULL || handleIndexPtr == NULL || size == 0) {
goto err; goto err;
} }
@ -240,16 +245,16 @@ bool heapBlockAllocate(Heap* heap, int* handleIndexPtr, int size, int a4)
goto err; goto err;
} }
HeapBlockHeader* blockHeader = (HeapBlockHeader*)block; blockHeader = (HeapBlockHeader*)block;
int state = blockHeader->state; state = blockHeader->state;
int handleIndex; int handleIndex;
if (!heapFindFreeHandle(heap, &handleIndex)) { if (!heapFindFreeHandle(heap, &handleIndex)) {
goto err_no_handle; goto err_no_handle;
} }
int blockSize = blockHeader->size; blockSize = blockHeader->size;
HeapHandle* handle = &(heap->handles[handleIndex]); handle = &(heap->handles[handleIndex]);
if (state == HEAP_BLOCK_STATE_SYSTEM) { if (state == HEAP_BLOCK_STATE_SYSTEM) {
// Bind block to handle. // Bind block to handle.
@ -591,6 +596,14 @@ bool heapFindFreeHandle(Heap* heap, int* handleIndexPtr)
// 0x453588 // 0x453588
bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4) bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4)
{ {
unsigned char* biggestFreeBlock;
HeapBlockHeader* biggestFreeBlockHeader;
int biggestFreeBlockSize;
HeapMoveableExtent* extent;
int reservedFreeBlockIndex;
HeapBlockHeader* blockHeader;
HeapBlockFooter* blockFooter;
if (!heapBuildFreeBlocksList(heap)) { if (!heapBuildFreeBlocksList(heap)) {
goto system; goto system;
} }
@ -604,9 +617,9 @@ bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4)
} }
// Take last free block (the biggest one). // Take last free block (the biggest one).
unsigned char* biggestFreeBlock = gHeapFreeBlocks[heap->freeBlocks - 1]; biggestFreeBlock = gHeapFreeBlocks[heap->freeBlocks - 1];
HeapBlockHeader* biggestFreeBlockHeader = (HeapBlockHeader*)biggestFreeBlock; biggestFreeBlockHeader = (HeapBlockHeader*)biggestFreeBlock;
int biggestFreeBlockSize = biggestFreeBlockHeader->size; biggestFreeBlockSize = biggestFreeBlockHeader->size;
// Make sure it can encompass new block of given size. // Make sure it can encompass new block of given size.
if (biggestFreeBlockSize >= size) { if (biggestFreeBlockSize >= size) {
@ -753,8 +766,8 @@ bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4)
goto system; goto system;
} }
HeapMoveableExtent* extent = &(gHeapMoveableExtents[extentIndex]); extent = &(gHeapMoveableExtents[extentIndex]);
int reservedFreeBlockIndex = 0; reservedFreeBlockIndex = 0;
for (int moveableBlockIndex = 0; moveableBlockIndex < extent->moveableBlocksLength; moveableBlockIndex++) { for (int moveableBlockIndex = 0; moveableBlockIndex < extent->moveableBlocksLength; moveableBlockIndex++) {
unsigned char* moveableBlock = gHeapMoveableBlocks[moveableBlockIndex]; unsigned char* moveableBlock = gHeapMoveableBlocks[moveableBlockIndex];
HeapBlockHeader* moveableBlockHeader = (HeapBlockHeader*)moveableBlock; HeapBlockHeader* moveableBlockHeader = (HeapBlockHeader*)moveableBlock;
@ -807,13 +820,13 @@ bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4)
heap->freeSize += (extent->blocksLength - 1) * HEAP_BLOCK_OVERHEAD_SIZE; heap->freeSize += (extent->blocksLength - 1) * HEAP_BLOCK_OVERHEAD_SIZE;
// Create one free block from entire moveable extent. // Create one free block from entire moveable extent.
HeapBlockHeader* blockHeader = (HeapBlockHeader*)extent->data; blockHeader = (HeapBlockHeader*)extent->data;
blockHeader->guard = HEAP_BLOCK_HEADER_GUARD; blockHeader->guard = HEAP_BLOCK_HEADER_GUARD;
blockHeader->size = extent->size + (extent->blocksLength - 1) * HEAP_BLOCK_OVERHEAD_SIZE; blockHeader->size = extent->size + (extent->blocksLength - 1) * HEAP_BLOCK_OVERHEAD_SIZE;
blockHeader->state = HEAP_BLOCK_STATE_FREE; blockHeader->state = HEAP_BLOCK_STATE_FREE;
blockHeader->handle_index = -1; blockHeader->handle_index = -1;
HeapBlockFooter* blockFooter = (HeapBlockFooter*)(extent->data + blockHeader->size + HEAP_BLOCK_HEADER_SIZE); blockFooter = (HeapBlockFooter*)(extent->data + blockHeader->size + HEAP_BLOCK_HEADER_SIZE);
blockFooter->guard = HEAP_BLOCK_FOOTER_GUARD; blockFooter->guard = HEAP_BLOCK_FOOTER_GUARD;
*blockPtr = extent->data; *blockPtr = extent->data;

View File

@ -103,6 +103,8 @@ int movieEffectsLoad(const char* filePath)
strcpy(path + strlen(path), ".cfg"); strcpy(path + strlen(path), ".cfg");
int* movieEffectFrameList;
if (!configRead(&config, path, true)) { if (!configRead(&config, path, true)) {
goto out; goto out;
} }
@ -112,7 +114,7 @@ int movieEffectsLoad(const char* filePath)
goto out; goto out;
} }
int* movieEffectFrameList = (int*)internal_malloc(sizeof(*movieEffectFrameList) * movieEffectsLength); movieEffectFrameList = (int*)internal_malloc(sizeof(*movieEffectFrameList) * movieEffectsLength);
if (movieEffectFrameList == NULL) { if (movieEffectFrameList == NULL) {
goto out; goto out;
} }

View File

@ -120,6 +120,7 @@ int textFontLoad(int font)
textFontDescriptor->glyphs = NULL; textFontDescriptor->glyphs = NULL;
File* stream = fileOpen(path, "rb"); File* stream = fileOpen(path, "rb");
int dataSize;
if (stream == NULL) { if (stream == NULL) {
goto out; goto out;
} }
@ -137,7 +138,7 @@ int textFontLoad(int font)
goto out; goto out;
} }
int dataSize = textFontDescriptor->lineHeight * ((textFontDescriptor->glyphs[textFontDescriptor->glyphCount - 1].width + 7) >> 3) + textFontDescriptor->glyphs[textFontDescriptor->glyphCount - 1].dataOffset; dataSize = textFontDescriptor->lineHeight * ((textFontDescriptor->glyphs[textFontDescriptor->glyphCount - 1].width + 7) >> 3) + textFontDescriptor->glyphs[textFontDescriptor->glyphCount - 1].dataOffset;
textFontDescriptor->data = (unsigned char*)internal_malloc(dataSize); textFontDescriptor->data = (unsigned char*)internal_malloc(dataSize);
if (textFontDescriptor->data == NULL) { if (textFontDescriptor->data == NULL) {
goto out; goto out;