(svn r26509) -Codechange: replace strdup with stredup (the latter ensures the return is not NULL)
This commit is contained in:
@@ -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 */
|
||||
|
@@ -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;
|
||||
|
@@ -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
|
||||
|
@@ -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)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user