From 6929e054a94bc0b2bcf5b7068cbe06a3f8cc8a86 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sun, 29 May 2022 00:32:50 +0300 Subject: [PATCH] Reorganize variables scope for goto Fixes AppleClang complaints. See #17 --- src/heap.cc | 35 ++++++++++++++++++++++++----------- src/movie_effect.cc | 4 +++- src/text_font.cc | 3 ++- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/heap.cc b/src/heap.cc index 9028f7a..3bd9de3 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -227,6 +227,11 @@ bool heapHandleListInit(Heap* heap) // 0x452AD0 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) { goto err; } @@ -240,16 +245,16 @@ bool heapBlockAllocate(Heap* heap, int* handleIndexPtr, int size, int a4) goto err; } - HeapBlockHeader* blockHeader = (HeapBlockHeader*)block; - int state = blockHeader->state; + blockHeader = (HeapBlockHeader*)block; + state = blockHeader->state; int handleIndex; if (!heapFindFreeHandle(heap, &handleIndex)) { goto err_no_handle; } - int blockSize = blockHeader->size; - HeapHandle* handle = &(heap->handles[handleIndex]); + blockSize = blockHeader->size; + handle = &(heap->handles[handleIndex]); if (state == HEAP_BLOCK_STATE_SYSTEM) { // Bind block to handle. @@ -591,6 +596,14 @@ bool heapFindFreeHandle(Heap* heap, int* handleIndexPtr) // 0x453588 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)) { goto system; } @@ -604,9 +617,9 @@ bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4) } // Take last free block (the biggest one). - unsigned char* biggestFreeBlock = gHeapFreeBlocks[heap->freeBlocks - 1]; - HeapBlockHeader* biggestFreeBlockHeader = (HeapBlockHeader*)biggestFreeBlock; - int biggestFreeBlockSize = biggestFreeBlockHeader->size; + biggestFreeBlock = gHeapFreeBlocks[heap->freeBlocks - 1]; + biggestFreeBlockHeader = (HeapBlockHeader*)biggestFreeBlock; + biggestFreeBlockSize = biggestFreeBlockHeader->size; // Make sure it can encompass new block of given size. if (biggestFreeBlockSize >= size) { @@ -753,8 +766,8 @@ bool heapFindFreeBlock(Heap* heap, int size, void** blockPtr, int a4) goto system; } - HeapMoveableExtent* extent = &(gHeapMoveableExtents[extentIndex]); - int reservedFreeBlockIndex = 0; + extent = &(gHeapMoveableExtents[extentIndex]); + reservedFreeBlockIndex = 0; for (int moveableBlockIndex = 0; moveableBlockIndex < extent->moveableBlocksLength; moveableBlockIndex++) { unsigned char* moveableBlock = gHeapMoveableBlocks[moveableBlockIndex]; 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; // Create one free block from entire moveable extent. - HeapBlockHeader* blockHeader = (HeapBlockHeader*)extent->data; + blockHeader = (HeapBlockHeader*)extent->data; blockHeader->guard = HEAP_BLOCK_HEADER_GUARD; blockHeader->size = extent->size + (extent->blocksLength - 1) * HEAP_BLOCK_OVERHEAD_SIZE; blockHeader->state = HEAP_BLOCK_STATE_FREE; 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; *blockPtr = extent->data; diff --git a/src/movie_effect.cc b/src/movie_effect.cc index 807310e..fc6ce73 100644 --- a/src/movie_effect.cc +++ b/src/movie_effect.cc @@ -103,6 +103,8 @@ int movieEffectsLoad(const char* filePath) strcpy(path + strlen(path), ".cfg"); + int* movieEffectFrameList; + if (!configRead(&config, path, true)) { goto out; } @@ -112,7 +114,7 @@ int movieEffectsLoad(const char* filePath) goto out; } - int* movieEffectFrameList = (int*)internal_malloc(sizeof(*movieEffectFrameList) * movieEffectsLength); + movieEffectFrameList = (int*)internal_malloc(sizeof(*movieEffectFrameList) * movieEffectsLength); if (movieEffectFrameList == NULL) { goto out; } diff --git a/src/text_font.cc b/src/text_font.cc index e9facec..cd43447 100644 --- a/src/text_font.cc +++ b/src/text_font.cc @@ -120,6 +120,7 @@ int textFontLoad(int font) textFontDescriptor->glyphs = NULL; File* stream = fileOpen(path, "rb"); + int dataSize; if (stream == NULL) { goto out; } @@ -137,7 +138,7 @@ int textFontLoad(int font) 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); if (textFontDescriptor->data == NULL) { goto out;