* 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-861f7616d084master
parent
7d42778f80
commit
f6a6179569
|
@ -67,9 +67,8 @@ static BOOL strresAllocBlock(STR_BLOCK **ppsBlock, UDWORD size)
|
||||||
}
|
}
|
||||||
memset((*ppsBlock)->apStrings, 0, sizeof(char *) * size);
|
memset((*ppsBlock)->apStrings, 0, sizeof(char *) * size);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG_CHECK_FOR_UNUSED_STRINGS
|
||||||
(*ppsBlock)->aUsage = (UDWORD*)malloc(sizeof(UDWORD) * size);
|
(*ppsBlock)->aUsage = (UDWORD*)calloc(sizeof(*(*ppsBlock)->aUsage) * size);
|
||||||
memset((*ppsBlock)->aUsage, 0, sizeof(UDWORD) * size);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -157,11 +156,11 @@ void strresDestroy(STR_RES *psRes)
|
||||||
{
|
{
|
||||||
for(i=psBlock->idStart; i<=psBlock->idEnd; i++)
|
for(i=psBlock->idStart; i<=psBlock->idEnd; i++)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_GROUP0
|
#ifdef DEBUG_CHECK_FOR_UNUSED_STRINGS
|
||||||
if (psBlock->aUsage[i - psBlock->idStart] == 0
|
if (psBlock->aUsage[i - psBlock->idStart] == 0
|
||||||
&& i != 0 && i < psRes->nextID)
|
&& 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
|
#endif
|
||||||
if (psBlock->apStrings[i - psBlock->idStart])
|
if (psBlock->apStrings[i - psBlock->idStart])
|
||||||
|
@ -177,7 +176,7 @@ void strresDestroy(STR_RES *psRes)
|
||||||
}
|
}
|
||||||
psNext = psBlock->psNext;
|
psNext = psBlock->psNext;
|
||||||
free(psBlock->apStrings);
|
free(psBlock->apStrings);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG_CHECK_FOR_UNUSED_STRINGS
|
||||||
free(psBlock->aUsage);
|
free(psBlock->aUsage);
|
||||||
#endif
|
#endif
|
||||||
free(psBlock);
|
free(psBlock);
|
||||||
|
@ -330,7 +329,7 @@ char *strresGetString(STR_RES *psRes, UDWORD id)
|
||||||
ASSERT( psBlock->apStrings[id - psBlock->idStart] != NULL,
|
ASSERT( psBlock->apStrings[id - psBlock->idStart] != NULL,
|
||||||
"strresGetString: String not found" );
|
"strresGetString: String not found" );
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG_CHECK_FOR_UNUSED_STRINGS
|
||||||
psBlock->aUsage[id - psBlock->idStart] += 1;
|
psBlock->aUsage[id - psBlock->idStart] += 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ typedef struct _str_block
|
||||||
char **apStrings;
|
char **apStrings;
|
||||||
UDWORD idStart, idEnd;
|
UDWORD idStart, idEnd;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG_CHECK_FOR_UNUSED_STRINGS
|
||||||
UDWORD *aUsage;
|
unsigned int* aUsage;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct _str_block *psNext;
|
struct _str_block *psNext;
|
||||||
|
|
Loading…
Reference in New Issue