* Change strresGetIDString to return its ID string const

* Change allocateName to do as the name suggests and actually ''allocate'' a string!

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5656 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-07-24 16:13:08 +00:00
parent e3a7f0cab8
commit 8101f3bf5b
3 changed files with 13 additions and 4 deletions

View File

@ -233,7 +233,7 @@ BOOL strresGetIDNum(STR_RES *psRes, const char *pIDStr, UDWORD *pIDNum)
/* Return the ID stored ID string that matches the string passed in */ /* Return the ID stored ID string that matches the string passed in */
char* strresGetIDString(STR_RES *psRes, const char *pIDStr) const char* strresGetIDString(STR_RES *psRes, const char *pIDStr)
{ {
STR_ID *psID; STR_ID *psID;

View File

@ -39,7 +39,7 @@ extern BOOL strresGetIDNum(struct STR_RES *psRes, const char *pIDStr, UDWORD *pI
* @return The stored ID string that matches the string passed in, or NULL if * @return The stored ID string that matches the string passed in, or NULL if
* no ID string could be found. * no ID string could be found.
*/ */
extern char* strresGetIDString(struct STR_RES *psRes, const char *pIDStr); extern const char* strresGetIDString(struct STR_RES *psRes, const char *pIDStr);
/* Get the string from an ID number */ /* Get the string from an ID number */
extern char *strresGetString(struct STR_RES *psRes, UDWORD id); extern char *strresGetString(struct STR_RES *psRes, UDWORD id);

View File

@ -2824,15 +2824,24 @@ and stores the name. Eventually ALL names will be 'resourced' for translation
*/ */
char* allocateName(const char* name) char* allocateName(const char* name)
{ {
char* const storeName = strresGetIDString(psStringRes, name); char const * const idStr = strresGetIDString(psStringRes, name);
char * storeName;
if (!storeName) if (!idStr)
{ {
debug(LOG_ERROR, "Unable to find string resource for %s", name); debug(LOG_ERROR, "Unable to find string resource for %s", name);
abort(); abort();
return NULL; return NULL;
} }
storeName = strdup(idStr);
if (!storeName)
{
debug(LOG_ERROR, "Out of memory");
abort();
return NULL;
}
return storeName; return storeName;
} }