From f1811e6b3ca4d666cfcbde8e09b032958b5f018a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 1 Oct 2025 01:32:30 +0100 Subject: [PATCH] Refactor variable declarations for improved scope and clarity in multiple source files --- src/blocks/data.c | 5 ++--- src/blocks/dump.c | 3 +-- src/close.c | 3 +-- src/ddt/ddt_v2.c | 2 +- src/lru.c | 3 ++- tool/ecc_cd.c | 3 +-- tool/info.c | 4 ++-- 7 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/blocks/data.c b/src/blocks/data.c index c2c3aa6..739d77e 100644 --- a/src/blocks/data.c +++ b/src/blocks/data.c @@ -80,9 +80,7 @@ int32_t process_data_block(aaruformatContext *ctx, IndexEntry *entry) mediaTagEntry *old_media_tag = NULL; mediaTagEntry *media_tag = NULL; uint8_t *data = NULL; - int error_no = 0; uint8_t lzma_properties[LZMA_PROPERTIES_LENGTH]; - uint64_t crc64 = 0; // Check if the context and image stream are valid if(ctx == NULL || ctx->imageStream == NULL) @@ -154,6 +152,7 @@ int32_t process_data_block(aaruformatContext *ctx, IndexEntry *entry) if(block_header.compression == Lzma || block_header.compression == LzmaClauniaSubchannelTransform) { + int error_no = 0; if(block_header.compression == LzmaClauniaSubchannelTransform && block_header.type != CdSectorSubchannel) { TRACE("Invalid compression type %d for block with data type %d, continuing...", block_header.compression, @@ -283,7 +282,7 @@ int32_t process_data_block(aaruformatContext *ctx, IndexEntry *entry) if(block_header.length > 0) { - crc64 = aaruf_crc64_data(data, block_header.length); + uint64_t crc64 = aaruf_crc64_data(data, block_header.length); // Due to how C# wrote it, it is effectively reversed if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64); diff --git a/src/blocks/dump.c b/src/blocks/dump.c index 0f5c725..248f7eb 100644 --- a/src/blocks/dump.c +++ b/src/blocks/dump.c @@ -37,7 +37,6 @@ void process_dumphw_block(aaruformatContext *ctx, const IndexEntry *entry) TRACE("Entering process_dumphw_block(%p, %p)", ctx, entry); int pos = 0; size_t read_bytes = 0; - uint64_t crc64 = 0; uint16_t e = 0; uint8_t *data = NULL; @@ -93,7 +92,7 @@ void process_dumphw_block(aaruformatContext *ctx, const IndexEntry *entry) if(read_bytes == ctx->dumpHardwareHeader.length) { - crc64 = aaruf_crc64_data(data, ctx->dumpHardwareHeader.length); + uint64_t crc64 = aaruf_crc64_data(data, ctx->dumpHardwareHeader.length); // Due to how C# wrote it, it is effectively reversed if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64); diff --git a/src/close.c b/src/close.c index 6c06876..efe29e3 100644 --- a/src/close.c +++ b/src/close.c @@ -126,7 +126,6 @@ int aaruf_close(void *context) { TRACE("Entering aaruf_close(%p)", context); - int i = 0; mediaTagEntry *media_tag = NULL; mediaTagEntry *tmp_media_tag = NULL; @@ -661,7 +660,7 @@ int aaruf_close(void *context) if(ctx->dumpHardwareEntriesWithData != NULL) { - for(i = 0; i < ctx->dumpHardwareHeader.entries; i++) + for(int i = 0; i < ctx->dumpHardwareHeader.entries; i++) { free(ctx->dumpHardwareEntriesWithData[i].extents); ctx->dumpHardwareEntriesWithData[i].extents = NULL; diff --git a/src/ddt/ddt_v2.c b/src/ddt/ddt_v2.c index 7131139..0ec3ae5 100644 --- a/src/ddt/ddt_v2.c +++ b/src/ddt/ddt_v2.c @@ -763,7 +763,6 @@ int32_t decode_ddt_multi_level_v2(aaruformatContext *ctx, uint64_t sector_addres size_t lzma_size = 0; uint8_t *cmp_data = NULL; uint8_t *buffer = NULL; - int32_t error_no = 0; crc64_ctx *crc64_context = NULL; uint64_t crc64 = 0; int items_per_ddt_entry = 0; @@ -810,6 +809,7 @@ int32_t decode_ddt_multi_level_v2(aaruformatContext *ctx, uint64_t sector_addres // Is the one we have cached the same as the one we need to read? if(ctx->cachedDdtOffset != secondary_ddt_offset) { + int32_t error_no = 0; fseek(ctx->imageStream, secondary_ddt_offset, SEEK_SET); DdtHeader2 ddt_header; size_t read_bytes = fread(&ddt_header, 1, sizeof(DdtHeader2), ctx->imageStream); diff --git a/src/lru.c b/src/lru.c index 0d58d3b..4b686f1 100644 --- a/src/lru.c +++ b/src/lru.c @@ -46,7 +46,7 @@ void *find_in_cache(struct CacheHeader *cache, const char *key) */ void add_to_cache(struct CacheHeader *cache, const char *key, void *value) { - struct CacheEntry *entry, *tmp_entry; + struct CacheEntry *entry; // TODO: Is this needed or we're just losing cycles? uthash does not free the entry entry = malloc(sizeof(struct CacheEntry)); entry->key = strdup(key); @@ -56,6 +56,7 @@ void add_to_cache(struct CacheHeader *cache, const char *key, void *value) // prune the cache to MAX_CACHE_SIZE if(HASH_COUNT(cache->cache) >= cache->max_items) { + struct CacheEntry *tmp_entry; HASH_ITER(hh, cache->cache, entry, tmp_entry) { // prune the first entry (loop is based on insertion order so this deletes the oldest item) diff --git a/tool/ecc_cd.c b/tool/ecc_cd.c index bc8b87c..ba6ccba 100644 --- a/tool/ecc_cd.c +++ b/tool/ecc_cd.c @@ -25,7 +25,6 @@ bool check_cd_sector_channel(CdEccContext *context, uint8_t *sector, bool *unknown, bool *has_edc, bool *edc_correct, bool *has_ecc_p, bool *ecc_p_correct, bool *has_ecc_q, bool *ecc_q_correct) { - int i = 0; uint32_t storedEdc = 0, edc = 0, calculatedEdc = 0; int size = 0, pos = 0; uint8_t zeroaddress[4]; @@ -48,7 +47,7 @@ bool check_cd_sector_channel(CdEccContext *context, uint8_t *sector, bool *unkno if((sector[0x00F] & 0x03) == 0x00) // Mode 0 { - for(i = 0x010; i < 0x930; i++) + for(int i = 0x010; i < 0x930; i++) if(sector[i] != 0x00) { fprintf(stderr, "Mode 0 sector with error at address: %2X:%2X:%2X.\n", sector[0x00C], sector[0x00D], diff --git a/tool/info.c b/tool/info.c index b22baf2..32af767 100644 --- a/tool/info.c +++ b/tool/info.c @@ -32,7 +32,7 @@ int info(const char *path) aaruformatContext *ctx = NULL; char *strBuffer = NULL; UErrorCode u_error_code = U_ZERO_ERROR; - uint i = 0, j = 0; + uint i = 0; mediaTagEntry const *mediaTag = NULL; mediaTagEntry const *tmpMediaTag = NULL; UChar ustr[128]; @@ -372,7 +372,7 @@ int info(const char *path) free(strBuffer); } - for(j = 0; j < ctx->dumpHardwareEntriesWithData[i].entry.extents; j++) + for(uint j = 0; j < ctx->dumpHardwareEntriesWithData[i].entry.extents; j++) { printf("\t\tExtent %d:\n", j); printf("\t\t\tStart: %llu\n", ctx->dumpHardwareEntriesWithData[i].extents[j].start);