From 8101f3bf5b023bd8cc2573cf6d8d849de2d9fd29 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Thu, 24 Jul 2008 16:13:08 +0000 Subject: [PATCH] * 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 --- lib/framework/strres.c | 2 +- lib/framework/strres.h | 2 +- src/stats.c | 13 +++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/framework/strres.c b/lib/framework/strres.c index 50c0d2bfd..8080b0302 100644 --- a/lib/framework/strres.c +++ b/lib/framework/strres.c @@ -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 */ -char* strresGetIDString(STR_RES *psRes, const char *pIDStr) +const char* strresGetIDString(STR_RES *psRes, const char *pIDStr) { STR_ID *psID; diff --git a/lib/framework/strres.h b/lib/framework/strres.h index b25393169..5674df736 100644 --- a/lib/framework/strres.h +++ b/lib/framework/strres.h @@ -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 * 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 */ extern char *strresGetString(struct STR_RES *psRes, UDWORD id); diff --git a/src/stats.c b/src/stats.c index 9be1c2470..1f97f7fe0 100644 --- a/src/stats.c +++ b/src/stats.c @@ -2824,15 +2824,24 @@ and stores the name. Eventually ALL names will be 'resourced' for translation */ 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); abort(); return NULL; } + storeName = strdup(idStr); + if (!storeName) + { + debug(LOG_ERROR, "Out of memory"); + abort(); + return NULL; + } + return storeName; }