From f6a6179569b3dac252bd74214e9c98479513e441 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Mon, 21 Jul 2008 00:57:32 +0000 Subject: [PATCH] * Use calloc instead of malloc followed by memset(0) * Use an unsigned int instead of UDWORD as we don't depend on the size guarantee * Move the definition of aUsage into #ifdef DEBUG_CHECK_FOR_UNUSED_STRINGS, because that's the only place where it's used git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5630 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/framework/strres.c | 13 ++++++------- lib/framework/strres.h | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/framework/strres.c b/lib/framework/strres.c index 8a0a2a055..2abbf9c35 100644 --- a/lib/framework/strres.c +++ b/lib/framework/strres.c @@ -67,9 +67,8 @@ static BOOL strresAllocBlock(STR_BLOCK **ppsBlock, UDWORD size) } memset((*ppsBlock)->apStrings, 0, sizeof(char *) * size); -#ifdef DEBUG - (*ppsBlock)->aUsage = (UDWORD*)malloc(sizeof(UDWORD) * size); - memset((*ppsBlock)->aUsage, 0, sizeof(UDWORD) * size); +#ifdef DEBUG_CHECK_FOR_UNUSED_STRINGS + (*ppsBlock)->aUsage = (UDWORD*)calloc(sizeof(*(*ppsBlock)->aUsage) * size); #endif return true; @@ -157,11 +156,11 @@ void strresDestroy(STR_RES *psRes) { for(i=psBlock->idStart; i<=psBlock->idEnd; i++) { -#ifdef DEBUG_GROUP0 +#ifdef DEBUG_CHECK_FOR_UNUSED_STRINGS if (psBlock->aUsage[i - psBlock->idStart] == 0 && i != 0 && i < psRes->nextID) { -// debug( LOG_NEVER, "strresDestroy: String id %d not used:\n \"%s\"\n", i, psBlock->apStrings[i - psBlock->idStart] ); + debug( LOG_NEVER, "strresDestroy: String id %d not used:\n \"%s\"\n", i, psBlock->apStrings[i - psBlock->idStart] ); } #endif if (psBlock->apStrings[i - psBlock->idStart]) @@ -177,7 +176,7 @@ void strresDestroy(STR_RES *psRes) } psNext = psBlock->psNext; free(psBlock->apStrings); -#ifdef DEBUG +#ifdef DEBUG_CHECK_FOR_UNUSED_STRINGS free(psBlock->aUsage); #endif free(psBlock); @@ -330,7 +329,7 @@ char *strresGetString(STR_RES *psRes, UDWORD id) ASSERT( psBlock->apStrings[id - psBlock->idStart] != NULL, "strresGetString: String not found" ); -#ifdef DEBUG +#ifdef DEBUG_CHECK_FOR_UNUSED_STRINGS psBlock->aUsage[id - psBlock->idStart] += 1; #endif diff --git a/lib/framework/strres.h b/lib/framework/strres.h index e8a13283f..0cb865e0d 100644 --- a/lib/framework/strres.h +++ b/lib/framework/strres.h @@ -29,8 +29,8 @@ typedef struct _str_block char **apStrings; UDWORD idStart, idEnd; -#ifdef DEBUG - UDWORD *aUsage; +#ifdef DEBUG_CHECK_FOR_UNUSED_STRINGS + unsigned int* aUsage; #endif struct _str_block *psNext;