* Initialize global psStringRes to NULL
* Return the STR_RES* pointer from strresCreate and use NULL to indicate failure * Use size_t to store memory sizes in instead of UDWORD git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5644 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
4f3c6d39a4
commit
d430c4b44d
|
@ -82,16 +82,14 @@ static STR_BLOCK* strresAllocBlock(const size_t size)
|
|||
|
||||
|
||||
/* Initialise the string system */
|
||||
BOOL strresCreate(STR_RES **ppsRes, UDWORD init, UDWORD ext)
|
||||
STR_RES* strresCreate(size_t init, size_t ext)
|
||||
{
|
||||
STR_RES *psRes;
|
||||
|
||||
psRes = (STR_RES*)malloc(sizeof(STR_RES));
|
||||
STR_RES* const psRes = (STR_RES*)malloc(sizeof(*psRes));
|
||||
if (!psRes)
|
||||
{
|
||||
debug( LOG_ERROR, "strresCreate: Out of memory" );
|
||||
debug(LOG_ERROR, "Out of memory");
|
||||
abort();
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
psRes->init = init;
|
||||
psRes->ext = ext;
|
||||
|
@ -103,7 +101,7 @@ BOOL strresCreate(STR_RES **ppsRes, UDWORD init, UDWORD ext)
|
|||
debug(LOG_ERROR, "Out of memory");
|
||||
abort();
|
||||
free(psRes);
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
psRes->psStrings = strresAllocBlock(init);
|
||||
|
@ -111,15 +109,13 @@ BOOL strresCreate(STR_RES **ppsRes, UDWORD init, UDWORD ext)
|
|||
{
|
||||
treapDestroy(psRes->psIDTreap);
|
||||
free(psRes);
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
psRes->psStrings->psNext = NULL;
|
||||
psRes->psStrings->idStart = 0;
|
||||
psRes->psStrings->idEnd = init-1;
|
||||
|
||||
*ppsRes = psRes;
|
||||
|
||||
return true;
|
||||
return psRes;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -49,12 +49,12 @@ typedef struct _str_res
|
|||
{
|
||||
struct TREAP_NODE** psIDTreap; ///< The treap to store string identifiers
|
||||
STR_BLOCK* psStrings; ///< The store for the strings themselves
|
||||
UDWORD init,ext; ///< Sizes for the string blocks
|
||||
size_t init, ext; ///< Sizes for the string blocks
|
||||
UDWORD nextID; ///< The next free ID
|
||||
} STR_RES;
|
||||
|
||||
/* Create a string resource object */
|
||||
extern BOOL strresCreate(STR_RES **ppsRes, UDWORD init, UDWORD ext);
|
||||
extern STR_RES* strresCreate(size_t init, size_t ext);
|
||||
|
||||
/* Release a string resource object */
|
||||
extern void strresDestroy(STR_RES *psRes);
|
||||
|
|
|
@ -33,17 +33,14 @@
|
|||
|
||||
|
||||
/* The string resource object */
|
||||
STR_RES *psStringRes;
|
||||
STR_RES* psStringRes = NULL;
|
||||
|
||||
/* Initialise the string system */
|
||||
BOOL stringsInitialise(void)
|
||||
{
|
||||
if (!strresCreate(&psStringRes, STRING_INIT, STRING_EXT))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
psStringRes = strresCreate(STRING_INIT, STRING_EXT);
|
||||
|
||||
return true;
|
||||
return psStringRes != NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue