(svn r26509) -Codechange: replace strdup with stredup (the latter ensures the return is not NULL)

This commit is contained in:
rubidium
2014-04-25 15:40:32 +00:00
parent 0b159549d4
commit 034735a54c
70 changed files with 207 additions and 183 deletions

View File

@@ -12,6 +12,7 @@
#include "../stdafx.h"
#include "saveload_internal.h"
#include "../engine_base.h"
#include "../string_func.h"
#include <map>
#include "../safeguards.h"
@@ -107,7 +108,7 @@ void CopyTempEngineData()
e->preview_company = se->preview_company;
e->preview_wait = se->preview_wait;
e->company_avail = se->company_avail;
if (se->name != NULL) e->name = strdup(se->name);
if (se->name != NULL) e->name = stredup(se->name);
}
/* Get rid of temporary data */

View File

@@ -153,7 +153,7 @@ static void Load_GSTR()
LanguageStrings *ls = new LanguageStrings(_game_saveload_string != NULL ? _game_saveload_string : "");
for (uint i = 0; i < _game_saveload_strings; i++) {
SlObject(NULL, _game_language_string);
*ls->lines.Append() = strdup(_game_saveload_string != NULL ? _game_saveload_string : "");
*ls->lines.Append() = stredup(_game_saveload_string != NULL ? _game_saveload_string : "");
}
*_current_data->raw_strings.Append() = ls;

View File

@@ -527,11 +527,11 @@ void NORETURN SlError(StringID string, const char *extra_msg)
if (_sl.action == SLA_LOAD_CHECK) {
_load_check_data.error = string;
free(_load_check_data.error_data);
_load_check_data.error_data = (extra_msg == NULL) ? NULL : strdup(extra_msg);
_load_check_data.error_data = (extra_msg == NULL) ? NULL : stredup(extra_msg);
} else {
_sl.error_str = string;
free(_sl.extra_msg);
_sl.extra_msg = (extra_msg == NULL) ? NULL : strdup(extra_msg);
_sl.extra_msg = (extra_msg == NULL) ? NULL : stredup(extra_msg);
}
/* We have to NULL all pointers here; we might be in a state where

View File

@@ -94,10 +94,10 @@ char *CopyFromOldName(StringID id)
/* Terminate the new string and copy it back to the name array */
*strto = '\0';
return strdup(tmp);
return stredup(tmp);
} else {
/* Name will already be in UTF-8. */
return strdup(&_old_name_array[LEN_OLD_STRINGS * GB(id, 0, 9)]);
return stredup(&_old_name_array[LEN_OLD_STRINGS * GB(id, 0, 9)]);
}
}