summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-04-25 15:40:32 +0000
committerrubidium <rubidium@openttd.org>2014-04-25 15:40:32 +0000
commit9ed12b0f07edb342aaff21c130d325fd158a9d5b (patch)
treef42aa775396b4ebda4d119f76e80a77c180936c7
parent4227f495c51ea909707505ec2ef1c730a382965d (diff)
downloadopenttd-9ed12b0f07edb342aaff21c130d325fd158a9d5b.tar.xz
(svn r26509) -Codechange: replace strdup with stredup (the latter ensures the return is not NULL)
-rw-r--r--src/ai/ai_config.cpp3
-rw-r--r--src/ai/ai_info.cpp9
-rw-r--r--src/ai/ai_scanner.cpp2
-rw-r--r--src/base_consist.cpp3
-rw-r--r--src/base_media_func.h12
-rw-r--r--src/blitter/factory.hpp2
-rw-r--r--src/company_cmd.cpp4
-rw-r--r--src/console.cpp8
-rw-r--r--src/console_cmds.cpp2
-rw-r--r--src/console_gui.cpp2
-rw-r--r--src/depot_cmd.cpp2
-rw-r--r--src/driver.cpp2
-rw-r--r--src/engine.cpp2
-rw-r--r--src/error_gui.cpp4
-rw-r--r--src/fileio.cpp28
-rw-r--r--src/fontdetection.cpp2
-rw-r--r--src/game/game_text.cpp4
-rw-r--r--src/gamelog.cpp2
-rw-r--r--src/goal.cpp6
-rw-r--r--src/goal_gui.cpp3
-rw-r--r--src/group_cmd.cpp2
-rw-r--r--src/hotkeys.cpp4
-rw-r--r--src/ini_load.cpp4
-rw-r--r--src/misc_gui.cpp2
-rw-r--r--src/music/extmidi.cpp2
-rw-r--r--src/network/core/tcp_http.h2
-rw-r--r--src/network/network.cpp2
-rw-r--r--src/network/network_chat_gui.cpp2
-rw-r--r--src/network/network_server.cpp2
-rw-r--r--src/newgrf.cpp12
-rw-r--r--src/newgrf_config.cpp12
-rw-r--r--src/newgrf_gui.cpp4
-rw-r--r--src/newgrf_text.cpp2
-rw-r--r--src/news_gui.cpp2
-rw-r--r--src/openttd.cpp42
-rw-r--r--src/os/windows/win32.cpp10
-rw-r--r--src/osk_gui.cpp4
-rw-r--r--src/safeguards.h4
-rw-r--r--src/saveload/engine_sl.cpp3
-rw-r--r--src/saveload/game_sl.cpp2
-rw-r--r--src/saveload/saveload.cpp4
-rw-r--r--src/saveload/strings_sl.cpp4
-rw-r--r--src/script/api/script_controller.cpp2
-rw-r--r--src/script/api/script_error.cpp3
-rw-r--r--src/script/api/script_event_types.cpp12
-rw-r--r--src/script/api/script_event_types.hpp11
-rw-r--r--src/script/api/script_log.cpp3
-rw-r--r--src/script/api/script_object.cpp2
-rw-r--r--src/script/api/script_text.cpp12
-rw-r--r--src/script/api/script_text.hpp5
-rw-r--r--src/script/script_config.cpp10
-rw-r--r--src/script/script_info.cpp12
-rw-r--r--src/script/script_scanner.cpp8
-rw-r--r--src/script/squirrel.cpp2
-rw-r--r--src/script/squirrel_helper.hpp4
-rw-r--r--src/script/squirrel_std.cpp4
-rw-r--r--src/settings.cpp10
-rw-r--r--src/settings_gui.cpp2
-rw-r--r--src/signs_cmd.cpp4
-rw-r--r--src/station_cmd.cpp2
-rw-r--r--src/stdafx.h2
-rw-r--r--src/story.cpp8
-rw-r--r--src/strgen/strgen.cpp4
-rw-r--r--src/strgen/strgen_base.cpp10
-rw-r--r--src/strings.cpp8
-rw-r--r--src/subsidy.cpp3
-rw-r--r--src/town_cmd.cpp10
-rw-r--r--src/vehicle_cmd.cpp4
-rw-r--r--src/video/cocoa/cocoa_v.mm2
-rw-r--r--src/waypoint_cmd.cpp2
70 files changed, 207 insertions, 183 deletions
diff --git a/src/ai/ai_config.cpp b/src/ai/ai_config.cpp
index 65365f4d4..f920d3101 100644
--- a/src/ai/ai_config.cpp
+++ b/src/ai/ai_config.cpp
@@ -11,6 +11,7 @@
#include "../stdafx.h"
#include "../settings_type.h"
+#include "../string_func.h"
#include "ai.hpp"
#include "ai_config.hpp"
#include "ai_info.hpp"
@@ -109,7 +110,7 @@ void AIConfig::SetSetting(const char *name, int value)
if (it != this->settings.end()) {
(*it).second = value;
} else {
- this->settings[strdup(name)] = value;
+ this->settings[stredup(name)] = value;
}
return;
diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp
index 9c9f3b47e..e048a5457 100644
--- a/src/ai/ai_info.cpp
+++ b/src/ai/ai_info.cpp
@@ -15,6 +15,7 @@
#include "ai_info.hpp"
#include "ai_scanner.hpp"
#include "../debug.h"
+#include "../string_func.h"
#include "../rev.h"
#include "../safeguards.h"
@@ -71,8 +72,8 @@ template <> const char *GetClassName<AIInfo, ST_AI>() { return "AIInfo"; }
if (res != 0) return res;
ScriptConfigItem config = _start_date_config;
- config.name = strdup(config.name);
- config.description = strdup(config.description);
+ config.name = stredup(config.name);
+ config.description = stredup(config.description);
info->config_list.push_front(config);
if (info->engine->MethodExists(*info->SQ_instance, "MinVersionToLoad")) {
@@ -94,7 +95,7 @@ template <> const char *GetClassName<AIInfo, ST_AI>() { return "AIInfo"; }
return SQ_ERROR;
}
} else {
- info->api_version = strdup("0.7");
+ info->api_version = stredup("0.7");
}
/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
@@ -117,7 +118,7 @@ template <> const char *GetClassName<AIInfo, ST_AI>() { return "AIInfo"; }
char buf[8];
seprintf(buf, lastof(buf), "%d.%d", GB(_openttd_newgrf_version, 28, 4), GB(_openttd_newgrf_version, 24, 4));
- info->api_version = strdup(buf);
+ info->api_version = stredup(buf);
/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
sq_setinstanceup(vm, 2, NULL);
diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp
index 2d7ab4119..4eb207147 100644
--- a/src/ai/ai_scanner.cpp
+++ b/src/ai/ai_scanner.cpp
@@ -33,7 +33,7 @@ void AIScannerInfo::Initialize()
/* Create the dummy AI */
free(this->main_script);
- this->main_script = strdup("%_dummy");
+ this->main_script = stredup("%_dummy");
extern void Script_CreateDummyInfo(HSQUIRRELVM vm, const char *type, const char *dir);
Script_CreateDummyInfo(this->engine->GetVM(), "AI", "ai");
}
diff --git a/src/base_consist.cpp b/src/base_consist.cpp
index 805e1d58f..c7fcdec21 100644
--- a/src/base_consist.cpp
+++ b/src/base_consist.cpp
@@ -12,6 +12,7 @@
#include "stdafx.h"
#include "base_consist.h"
#include "vehicle_base.h"
+#include "string_func.h"
#include "safeguards.h"
@@ -29,7 +30,7 @@ void BaseConsist::CopyConsistPropertiesFrom(const BaseConsist *src)
if (this == src) return;
free(this->name);
- this->name = src->name != NULL ? strdup(src->name) : NULL;
+ this->name = src->name != NULL ? stredup(src->name) : NULL;
this->current_order_time = src->current_order_time;
this->lateness_counter = src->lateness_counter;
diff --git a/src/base_media_func.h b/src/base_media_func.h
index 6322ba1db..650506f90 100644
--- a/src/base_media_func.h
+++ b/src/base_media_func.h
@@ -51,16 +51,16 @@ bool BaseSet<T, Tnum_files, Tsearch_in_tars>::FillSetDetails(IniFile *ini, const
IniItem *item;
fetch_metadata("name");
- this->name = strdup(item->value);
+ this->name = stredup(item->value);
fetch_metadata("description");
- this->description[strdup("")] = strdup(item->value);
+ this->description[stredup("")] = stredup(item->value);
/* Add the translations of the descriptions too. */
for (const IniItem *item = metadata->item; item != NULL; item = item->next) {
if (strncmp("description.", item->name, 12) != 0) continue;
- this->description[strdup(item->name + 12)] = strdup(item->value);
+ this->description[stredup(item->name + 12)] = stredup(item->value);
}
fetch_metadata("shortname");
@@ -129,9 +129,9 @@ bool BaseSet<T, Tnum_files, Tsearch_in_tars>::FillSetDetails(IniFile *ini, const
if (item == NULL) item = origin->GetItem("default", false);
if (item == NULL) {
DEBUG(grf, 1, "No origin warning message specified for: %s", filename);
- file->missing_warning = strdup("");
+ file->missing_warning = stredup("");
} else {
- file->missing_warning = strdup(item->value);
+ file->missing_warning = stredup(item->value);
}
switch (T::CheckMD5(file, BASESET_DIR)) {
@@ -164,7 +164,7 @@ bool BaseMedia<Tbase_set>::AddFile(const char *filename, size_t basepath_length,
IniFile *ini = new IniFile();
ini->LoadFromDisk(filename, BASESET_DIR);
- char *path = strdup(filename + basepath_length);
+ char *path = stredup(filename + basepath_length);
char *psep = strrchr(path, PATHSEPCHAR);
if (psep != NULL) {
psep[1] = '\0';
diff --git a/src/blitter/factory.hpp b/src/blitter/factory.hpp
index cda470510..01faca68f 100644
--- a/src/blitter/factory.hpp
+++ b/src/blitter/factory.hpp
@@ -63,7 +63,7 @@ protected:
* @pre There is no blitter registered with this name.
*/
BlitterFactory(const char *name, const char *description, bool usable = true) :
- name(strdup(name)), description(strdup(description))
+ name(stredup(name)), description(stredup(description))
{
if (usable) {
/*
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index 97095d3c9..d83df30af 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -1114,7 +1114,7 @@ CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (flags & DC_EXEC) {
Company *c = Company::Get(_current_company);
free(c->name);
- c->name = reset ? NULL : strdup(text);
+ c->name = reset ? NULL : stredup(text);
MarkWholeScreenDirty();
CompanyAdminUpdate(c);
}
@@ -1163,7 +1163,7 @@ CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (reset) {
c->president_name = NULL;
} else {
- c->president_name = strdup(text);
+ c->president_name = stredup(text);
if (c->name_1 == STR_SV_UNNAMED && c->name == NULL) {
char buf[80];
diff --git a/src/console.cpp b/src/console.cpp
index 2274da64f..511019281 100644
--- a/src/console.cpp
+++ b/src/console.cpp
@@ -105,7 +105,7 @@ void IConsolePrint(TextColour colour_code, const char *string)
/* Create a copy of the string, strip if of colours and invalid
* characters and (when applicable) assign it to the console buffer */
- str = strdup(string);
+ str = stredup(string);
str_strip_colours(str);
str_validate(str, str + strlen(str));
@@ -256,7 +256,7 @@ char *RemoveUnderscores(char *name)
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc, IConsoleHook *hook)
{
IConsoleCmd *item_new = MallocT<IConsoleCmd>(1);
- item_new->name = RemoveUnderscores(strdup(name));
+ item_new->name = RemoveUnderscores(stredup(name));
item_new->next = NULL;
item_new->proc = proc;
item_new->hook = hook;
@@ -291,8 +291,8 @@ void IConsoleAliasRegister(const char *name, const char *cmd)
return;
}
- char *new_alias = RemoveUnderscores(strdup(name));
- char *cmd_aliased = strdup(cmd);
+ char *new_alias = RemoveUnderscores(stredup(name));
+ char *cmd_aliased = stredup(cmd);
IConsoleAlias *item_new = MallocT<IConsoleAlias>(1);
item_new->next = NULL;
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 4d4223f14..8d9e04113 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -1344,7 +1344,7 @@ DEF_CONSOLE_CMD(ConAlias)
IConsoleAliasRegister(argv[1], argv[2]);
} else {
free(alias->cmdline);
- alias->cmdline = strdup(argv[2]);
+ alias->cmdline = stredup(argv[2]);
}
return true;
}
diff --git a/src/console_gui.cpp b/src/console_gui.cpp
index d7ed1f690..4e454f476 100644
--- a/src/console_gui.cpp
+++ b/src/console_gui.cpp
@@ -465,7 +465,7 @@ static const char *IConsoleHistoryAdd(const char *cmd)
if (_iconsole_history[0] == NULL || strcmp(_iconsole_history[0], cmd) != 0) {
free(_iconsole_history[ICON_HISTORY_SIZE - 1]);
memmove(&_iconsole_history[1], &_iconsole_history[0], sizeof(_iconsole_history[0]) * (ICON_HISTORY_SIZE - 1));
- _iconsole_history[0] = strdup(cmd);
+ _iconsole_history[0] = stredup(cmd);
}
/* Reset the history position */
diff --git a/src/depot_cmd.cpp b/src/depot_cmd.cpp
index 77f76bd20..5101b7c2c 100644
--- a/src/depot_cmd.cpp
+++ b/src/depot_cmd.cpp
@@ -70,7 +70,7 @@ CommandCost CmdRenameDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
d->name = NULL;
MakeDefaultName(d);
} else {
- d->name = strdup(text);
+ d->name = stredup(text);
}
/* Update the orders and depot */
diff --git a/src/driver.cpp b/src/driver.cpp
index 818251e31..2e90c2df1 100644
--- a/src/driver.cpp
+++ b/src/driver.cpp
@@ -208,7 +208,7 @@ DriverFactoryBase::DriverFactoryBase(Driver::Type type, int priority, const char
strecpy(buf, GetDriverTypeName(type), lastof(buf));
strecpy(buf + 5, name, lastof(buf));
- const char *longname = strdup(buf);
+ const char *longname = stredup(buf);
std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(longname, this));
assert(P.second);
diff --git a/src/engine.cpp b/src/engine.cpp
index 03072869c..362bd014a 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -1027,7 +1027,7 @@ CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (reset) {
e->name = NULL;
} else {
- e->name = strdup(text);
+ e->name = stredup(text);
}
MarkWholeScreenDirty();
diff --git a/src/error_gui.cpp b/src/error_gui.cpp
index 34a49c74d..98988de5a 100644
--- a/src/error_gui.cpp
+++ b/src/error_gui.cpp
@@ -77,7 +77,7 @@ ErrorMessageData::ErrorMessageData(const ErrorMessageData &data)
*this = data;
for (size_t i = 0; i < lengthof(this->strings); i++) {
if (this->strings[i] != NULL) {
- this->strings[i] = strdup(this->strings[i]);
+ this->strings[i] = stredup(this->strings[i]);
this->decode_params[i] = (size_t)this->strings[i];
}
}
@@ -158,7 +158,7 @@ void ErrorMessageData::SetDParam(uint n, uint64 v)
void ErrorMessageData::SetDParamStr(uint n, const char *str)
{
free(this->strings[n]);
- this->strings[n] = strdup(str);
+ this->strings[n] = stredup(str);
}
/** Define a queue with errors. */
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 49da7b9b4..4ef4f1f93 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -265,7 +265,7 @@ void FioOpenFile(int slot, const char *filename, Subdirectory subdir)
/* Store the filename without path and extension */
const char *t = strrchr(filename, PATHSEPCHAR);
- _fio.shortnames[slot] = strdup(t == NULL ? filename : t);
+ _fio.shortnames[slot] = stredup(t == NULL ? filename : t);
char *t2 = strrchr(_fio.shortnames[slot], '.');
if (t2 != NULL) *t2 = '\0';
strtolower(_fio.shortnames[slot]);
@@ -755,7 +755,7 @@ bool TarScanner::AddFile(const char *filename, size_t basepath_length, const cha
* been given read access. */
if (f == NULL) return false;
- const char *dupped_filename = strdup(filename);
+ const char *dupped_filename = stredup(filename);
_tar_list[this->subdir][filename].filename = dupped_filename;
_tar_list[this->subdir][filename].dirname = NULL;
@@ -892,7 +892,7 @@ bool TarScanner::AddFile(const char *filename, size_t basepath_length, const cha
/* Store the first directory name we detect */
DEBUG(misc, 6, "Found dir in tar: %s", name);
- if (_tar_list[this->subdir][filename].dirname == NULL) _tar_list[this->subdir][filename].dirname = strdup(name);
+ if (_tar_list[this->subdir][filename].dirname == NULL) _tar_list[this->subdir][filename].dirname = stredup(name);
break;
default:
@@ -1091,7 +1091,7 @@ void DetermineBasePaths(const char *exe)
free(xdg_data_home);
AppendPathSeparator(tmp, lastof(tmp));
- _searchpaths[SP_PERSONAL_DIR_XDG] = strdup(tmp);
+ _searchpaths[SP_PERSONAL_DIR_XDG] = stredup(tmp);
#endif
#if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2) || !defined(WITH_PERSONAL_DIR)
_searchpaths[SP_PERSONAL_DIR] = NULL;
@@ -1099,7 +1099,7 @@ void DetermineBasePaths(const char *exe)
#ifdef __HAIKU__
BPath path;
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
- const char *homedir = strdup(path.Path());
+ const char *homedir = stredup(path.Path());
#else
/* getenv is highly unsafe; duplicate it as soon as possible,
* or at least before something else touches the environment
@@ -1112,7 +1112,7 @@ void DetermineBasePaths(const char *exe)
if (homedir == NULL) {
const struct passwd *pw = getpwuid(getuid());
- homedir = (pw == NULL) ? NULL : strdup(pw->pw_dir);
+ homedir = (pw == NULL) ? NULL : stredup(pw->pw_dir);
}
#endif
@@ -1121,7 +1121,7 @@ void DetermineBasePaths(const char *exe)
seprintf(tmp, lastof(tmp), "%s" PATHSEP "%s", homedir, PERSONAL_DIR);
AppendPathSeparator(tmp, lastof(tmp));
- _searchpaths[SP_PERSONAL_DIR] = strdup(tmp);
+ _searchpaths[SP_PERSONAL_DIR] = stredup(tmp);
free(homedir);
} else {
_searchpaths[SP_PERSONAL_DIR] = NULL;
@@ -1131,7 +1131,7 @@ void DetermineBasePaths(const char *exe)
#if defined(WITH_SHARED_DIR)
seprintf(tmp, lastof(tmp), "%s", SHARED_DIR);
AppendPathSeparator(tmp, lastof(tmp));
- _searchpaths[SP_SHARED_DIR] = strdup(tmp);
+ _searchpaths[SP_SHARED_DIR] = stredup(tmp);
#else
_searchpaths[SP_SHARED_DIR] = NULL;
#endif
@@ -1141,7 +1141,7 @@ void DetermineBasePaths(const char *exe)
#else
if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0';
AppendPathSeparator(tmp, lastof(tmp));
- _searchpaths[SP_WORKING_DIR] = strdup(tmp);
+ _searchpaths[SP_WORKING_DIR] = stredup(tmp);
#endif
_do_scan_working_directory = DoScanWorkingDirectory();
@@ -1150,7 +1150,7 @@ void DetermineBasePaths(const char *exe)
if (ChangeWorkingDirectoryToExecutable(exe)) {
if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0';
AppendPathSeparator(tmp, lastof(tmp));
- _searchpaths[SP_BINARY_DIR] = strdup(tmp);
+ _searchpaths[SP_BINARY_DIR] = stredup(tmp);
} else {
_searchpaths[SP_BINARY_DIR] = NULL;
}
@@ -1167,7 +1167,7 @@ void DetermineBasePaths(const char *exe)
#else
seprintf(tmp, lastof(tmp), "%s", GLOBAL_DATA_DIR);
AppendPathSeparator(tmp, lastof(tmp));
- _searchpaths[SP_INSTALLATION_DIR] = strdup(tmp);
+ _searchpaths[SP_INSTALLATION_DIR] = stredup(tmp);
#endif
#ifdef WITH_COCOA
extern void cocoaSetApplicationBundleDir();
@@ -1209,7 +1209,7 @@ void DeterminePaths(const char *exe)
char *config_dir;
if (_config_file != NULL) {
- config_dir = strdup(_config_file);
+ config_dir = stredup(_config_file);
char *end = strrchr(config_dir, PATHSEPCHAR);
if (end == NULL) {
config_dir[0] = '\0';
@@ -1221,7 +1221,7 @@ void DeterminePaths(const char *exe)
if (FioFindFullPath(personal_dir, lastof(personal_dir), BASE_DIR, "openttd.cfg") != NULL) {
char *end = strrchr(personal_dir, PATHSEPCHAR);
if (end != NULL) end[1] = '\0';
- config_dir = strdup(personal_dir);
+ config_dir = stredup(personal_dir);
_config_file = str_fmt("%sopenttd.cfg", config_dir);
} else {
#if defined(WITH_XDG_BASEDIR) && defined(WITH_PERSONAL_DIR)
@@ -1235,7 +1235,7 @@ void DeterminePaths(const char *exe)
config_dir = NULL;
for (uint i = 0; i < lengthof(new_openttd_cfg_order); i++) {
if (IsValidSearchPath(new_openttd_cfg_order[i])) {
- config_dir = strdup(_searchpaths[new_openttd_cfg_order[i]]);
+ config_dir = stredup(_searchpaths[new_openttd_cfg_order[i]]);
break;
}
}
diff --git a/src/fontdetection.cpp b/src/fontdetection.cpp
index bf97daabf..0033cdfa7 100644
--- a/src/fontdetection.cpp
+++ b/src/fontdetection.cpp
@@ -566,7 +566,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
char *font_family;
/* Split & strip the font's style */
- font_family = strdup(font_name);
+ font_family = stredup(font_name);
font_style = strchr(font_family, ',');
if (font_style != NULL) {
font_style[0] = '\0';
diff --git a/src/game/game_text.cpp b/src/game/game_text.cpp
index 30e630495..f717e2dc0 100644
--- a/src/game/game_text.cpp
+++ b/src/game/game_text.cpp
@@ -212,7 +212,7 @@ struct StringNameWriter : HeaderWriter {
void WriteStringID(const char *name, int stringid)
{
- if (stringid == (int)this->strings->Length()) *this->strings->Append() = strdup(name);
+ if (stringid == (int)this->strings->Length()) *this->strings->Append() = stredup(name);
}
void Finalise(const StringData &data)
@@ -231,7 +231,7 @@ private:
public:
/** Initialise */
- LanguageScanner(GameStrings *gs, const char *exclude) : gs(gs), exclude(strdup(exclude)) {}
+ LanguageScanner(GameStrings *gs, const char *exclude) : gs(gs), exclude(stredup(exclude)) {}
~LanguageScanner() { free(exclude); }
/**
diff --git a/src/gamelog.cpp b/src/gamelog.cpp
index c4334f478..400c0d22f 100644
--- a/src/gamelog.cpp
+++ b/src/gamelog.cpp
@@ -462,7 +462,7 @@ void GamelogSetting(const char *name, int32 oldval, int32 newval)
LoggedChange *lc = GamelogChange(GLCT_SETTING);
if (lc == NULL) return;
- lc->setting.name = strdup(name);
+ lc->setting.name = stredup(name);
lc->setting.oldval = oldval;
lc->setting.newval = newval;
}
diff --git a/src/goal.cpp b/src/goal.cpp
index d472fc2c5..2f6ca242a 100644
--- a/src/goal.cpp
+++ b/src/goal.cpp
@@ -90,7 +90,7 @@ CommandCost CmdCreateGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
g->type = type;
g->dst = p2;
g->company = company;
- g->text = strdup(text);
+ g->text = stredup(text);
g->progress = NULL;
g->completed = false;
@@ -155,7 +155,7 @@ CommandCost CmdSetGoalText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (flags & DC_EXEC) {
Goal *g = Goal::Get(p1);
free(g->text);
- g->text = strdup(text);
+ g->text = stredup(text);
if (g->company == INVALID_COMPANY) {
InvalidateWindowClassesData(WC_GOALS_LIST);
@@ -187,7 +187,7 @@ CommandCost CmdSetGoalProgress(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (StrEmpty(text)) {
g->progress = NULL;
} else {
- g->progress = strdup(text);
+ g->progress = stredup(text);
}
if (g->company == INVALID_COMPANY) {
diff --git a/src/goal_gui.cpp b/src/goal_gui.cpp
index cb38d7f6e..f98189d18 100644
--- a/src/goal_gui.cpp
+++ b/src/goal_gui.cpp
@@ -23,6 +23,7 @@
#include "company_base.h"
#include "story_base.h"
#include "command_func.h"
+#include "string_func.h"
#include "widgets/goal_widget.h"
@@ -364,7 +365,7 @@ struct GoalQuestionWindow : public Window {
GoalQuestionWindow(WindowDesc *desc, WindowNumber window_number, byte type, uint32 button_mask, const char *question) : Window(desc), type(type)
{
assert(type < GOAL_QUESTION_TYPE_COUNT);
- this->question = strdup(question);
+ this->question = stredup(question);
/* Figure out which buttons we have to enable. */
uint bit;
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp
index 1c5d05ae1..8712c378f 100644
--- a/src/group_cmd.cpp
+++ b/src/group_cmd.cpp
@@ -392,7 +392,7 @@ CommandCost CmdAlterGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Delete the old name */
free(g->name);
/* Assign the new one */
- g->name = reset ? NULL : strdup(text);
+ g->name = reset ? NULL : stredup(text);
}
} else {
/* Set group parent */
diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp
index 0579792e7..84288a0e8 100644
--- a/src/hotkeys.cpp
+++ b/src/hotkeys.cpp
@@ -141,7 +141,7 @@ static void ParseHotkeys(Hotkey *hotkey, const char *value)
* by a '+'.
* @param keycode The keycode to convert to a string.
* @return A string representation of this keycode.
- * @note The return value is a static buffer, strdup the result before calling
+ * @note The return value is a static buffer, stredup the result before calling
* this function again.
*/
static const char *KeycodeToString(uint16 keycode)
@@ -195,7 +195,7 @@ static const char *KeycodeToString(uint16 keycode)
* keycodes are attached to the hotkey they are split by a comma.
* @param hotkey The keycodes of this hotkey need to be converted to a string.
* @return A string representation of all keycodes.
- * @note The return value is a static buffer, strdup the result before calling
+ * @note The return value is a static buffer, stredup the result before calling
* this function again.
*/
const char *SaveKeycodes(const Hotkey *hotkey)
diff --git a/src/ini_load.cpp b/src/ini_load.cpp
index f90953a10..389dcab03 100644
--- a/src/ini_load.cpp
+++ b/src/ini_load.cpp
@@ -49,7 +49,7 @@ IniItem::~IniItem()
void IniItem::SetValue(const char *value)
{
free(this->value);
- this->value = strdup(value);
+ this->value = stredup(value);
}
/**
@@ -168,7 +168,7 @@ IniGroup *IniLoadFile::GetGroup(const char *name, size_t len, bool create_new)
/* otherwise make a new one */
IniGroup *group = new IniGroup(this, name, name + len - 1);
- group->comment = strdup("\n");
+ group->comment = stredup("\n");
return group;
}
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 52dba71b9..8810c2c0e 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -946,7 +946,7 @@ struct QueryStringWindow : public Window
this->editbox.text.UpdateSize();
- if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->editbox.orig = strdup(this->editbox.text.buf);
+ if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->editbox.orig = stredup(this->editbox.text.buf);
this->querystrings[WID_QS_TEXT] = &this->editbox;
this->editbox.caption = caption;
diff --git a/src/music/extmidi.cpp b/src/music/extmidi.cpp
index 6bfc990e5..919f689e0 100644
--- a/src/music/extmidi.cpp
+++ b/src/music/extmidi.cpp
@@ -45,7 +45,7 @@ const char *MusicDriver_ExtMidi::Start(const char * const * parm)
const char *command = GetDriverParam(parm, "cmd");
if (StrEmpty(command)) command = EXTERNAL_PLAYER;
- this->command = strdup(command);
+ this->command = stredup(command);
this->song[0] = '\0';
this->pid = -1;
return NULL;
diff --git a/src/network/core/tcp_http.h b/src/network/core/tcp_http.h
index 6222c7695..36520f136 100644
--- a/src/network/core/tcp_http.h
+++ b/src/network/core/tcp_http.h
@@ -96,7 +96,7 @@ public:
const char *data = NULL, int depth = 0) :
TCPConnecter(address),
callback(callback),
- url(strdup(url)),
+ url(stredup(url)),
data(data),
depth(depth)
{
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 5eefb850d..156859a40 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -653,7 +653,7 @@ void NetworkRebuildHostList()
_network_host_list.Clear();
for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
- if (item->manually) *_network_host_list.Append() = strdup(item->address.GetAddressAsString(false));
+ if (item->manually) *_network_host_list.Append() = stredup(item->address.GetAddressAsString(false));
}
}
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index b1a5dcb55..07224a9f1 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -391,7 +391,7 @@ struct NetworkChatWindow : public Window {
item = 0;
/* Copy the buffer so we can modify it without damaging the real data */
- pre_buf = (_chat_tab_completion_active) ? strdup(_chat_tab_completion_buf) : strdup(tb->buf);
+ pre_buf = (_chat_tab_completion_active) ? stredup(_chat_tab_completion_buf) : stredup(tb->buf);
tb_buf = ChatTabCompletionFindText(pre_buf);
tb_len = strlen(tb_buf);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 187dfdef8..84337f5f7 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -2102,7 +2102,7 @@ uint NetworkServerKickOrBanIP(const char *ip, bool ban)
break;
}
}
- if (!contains) *_network_ban_list.Append() = strdup(ip);
+ if (!contains) *_network_ban_list.Append() = stredup(ip);
}
uint n = 0;
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 079c12162..b1b6f5ff1 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -6006,7 +6006,7 @@ static void CfgApply(ByteReader *buf)
static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig *c)
{
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC, c);
- error->data = strdup(_cur.grfconfig->GetName());
+ error->data = stredup(_cur.grfconfig->GetName());
}
/* Action 0x07
@@ -6369,7 +6369,7 @@ static void GRFLoadError(ByteReader *buf)
error->custom_message = TranslateTTDPatchCodes(_cur.grffile->grfid, lang, true, message, NULL, SCC_RAW_STRING_POINTER);
} else {
grfmsg(7, "GRFLoadError: No custom message supplied.");
- error->custom_message = strdup("");
+ error->custom_message = stredup("");
}
} else {
error->message = msgstr[message_id];
@@ -6381,7 +6381,7 @@ static void GRFLoadError(ByteReader *buf)
error->data = TranslateTTDPatchCodes(_cur.grffile->grfid, lang, true, data);
} else {
grfmsg(7, "GRFLoadError: No message data supplied.");
- error->data = strdup("");
+ error->data = stredup("");
}
/* Only two parameter numbers can be used in the string. */
@@ -6890,7 +6890,7 @@ static void GRFInhibit(ByteReader *buf)
if (file != NULL && file != _cur.grfconfig) {
grfmsg(2, "GRFInhibit: Deactivating file '%s'", file->filename);
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_FORCEFULLY_DISABLED, file);
- error->data = strdup(_cur.grfconfig->GetName());
+ error->data = stredup(_cur.grfconfig->GetName());
}
}
}
@@ -7241,7 +7241,7 @@ static void TranslateGRFStrings(ByteReader *buf)
char tmp[256];
GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE, lastof(tmp));
- error->data = strdup(tmp);
+ error->data = stredup(tmp);
return;
}
@@ -8182,7 +8182,7 @@ static void InitNewGRFFile(const GRFConfig *config)
*/
GRFFile::GRFFile(const GRFConfig *config)
{
- this->filename = strdup(config->filename);
+ this->filename = stredup(config->filename);
this->grfid = config->ident.grfid;
/* Initialise local settings to defaults */
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 9250ce748..eb6322e32 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -50,7 +50,7 @@ GRFConfig::GRFConfig(const char *filename) :
url(new GRFTextWrapper()),
num_valid_params(lengthof(param))
{
- if (filename != NULL) this->filename = strdup(filename);
+ if (filename != NULL) this->filename = stredup(filename);
this->name->AddRef();
this->info->AddRef();
this->url->AddRef();
@@ -78,7 +78,7 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
{
MemCpyT<uint8>(this->original_md5sum, config.original_md5sum, lengthof(this->original_md5sum));
MemCpyT<uint32>(this->param, config.param, lengthof(this->param));
- if (config.filename != NULL) this->filename = strdup(config.filename);
+ if (config.filename != NULL) this->filename = stredup(config.filename);
this->name->AddRef();
this->info->AddRef();
this->url->AddRef();
@@ -95,7 +95,7 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
/** Cleanup a GRFConfig object. */
GRFConfig::~GRFConfig()
{
- /* GCF_COPY as in NOT strdupped/alloced the filename */
+ /* GCF_COPY as in NOT stredupped/alloced the filename */
if (!HasBit(this->flags, GCF_COPY)) {
free(this->filename);
delete this->error;
@@ -204,8 +204,8 @@ GRFError::GRFError(const GRFError &error) :
message(error.message),
severity(error.severity)
{
- if (error.custom_message != NULL) this->custom_message = strdup(error.custom_message);
- if (error.data != NULL) this->data = strdup(error.data);
+ if (error.custom_message != NULL) this->custom_message = stredup(error.custom_message);
+ if (error.data != NULL) this->data = stredup(error.data);
memcpy(this->param_value, error.param_value, sizeof(this->param_value));
}
@@ -584,7 +584,7 @@ compatible_grf:
* already a local one, so there is no need to replace it. */
if (!HasBit(c->flags, GCF_COPY)) {
free(c->filename);
- c->filename = strdup(f->filename);
+ c->filename = stredup(f->filename);
memcpy(c->ident.md5sum, f->ident.md5sum, sizeof(c->ident.md5sum));
c->name->Release();
c->name = f->name;
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index 9cbbded69..462360d59 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -2036,9 +2036,9 @@ struct ScanProgressWindow : public Window {
if (name == NULL) {
char buf[256];
GetString(buf, STR_NEWGRF_SCAN_ARCHIVES, lastof(buf));
- this->last_name = strdup(buf);
+ this->last_name = stredup(buf);
} else {
- this->last_name = strdup(name);
+ this->last_name = stredup(name);
}
this->scanned = num;
if (num > _settings_client.gui.last_newgrf_count) _settings_client.gui.last_newgrf_count = num;
diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp
index cb6b57fa6..549353122 100644
--- a/src/newgrf_text.cpp
+++ b/src/newgrf_text.cpp
@@ -231,7 +231,7 @@ struct UnmappedChoiceList : ZeroedMemoryAllocator {
/* In case of a (broken) NewGRF without a default,
* assume an empty string. */
grfmsg(1, "choice list misses default value");
- this->strings[0] = strdup("");
+ this->strings[0] = stredup("");
}
char *d = old_d;
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 77fc5828d..7098b315b 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -726,7 +726,7 @@ CommandCost CmdCustomNewsItem(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
if (company != INVALID_OWNER && company != _local_company) return CommandCost();
if (flags & DC_EXEC) {
- char *news = strdup(text);
+ char *news = stredup(text);
SetDParamStr(0, news);
AddNewsItem(STR_NEWS_CUSTOM_ITEM, type, NF_NORMAL, reftype1, p2, NR_NONE, UINT32_MAX, news);
}
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 57e32489d..5f8ecc9ff 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -444,7 +444,7 @@ struct AfterNewGRFScan : NewGRFScanCallback {
#if defined(ENABLE_NETWORK)
if (dedicated_host != NULL) {
_network_bind_list.Clear();
- *_network_bind_list.Append() = strdup(dedicated_host);
+ *_network_bind_list.Append() = stredup(dedicated_host);
}
if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port;
#endif /* ENABLE_NETWORK */
@@ -563,23 +563,23 @@ int openttd_main(int argc, char *argv[])
int i;
while ((i = mgo.GetOpt()) != -1) {
switch (i) {
- case 'I': free(graphics_set); graphics_set = strdup(mgo.opt); break;
- case 'S': free(sounds_set); sounds_set = strdup(mgo.opt); break;
- case 'M': free(music_set); music_set = strdup(mgo.opt); break;
- case 'm': free(musicdriver); musicdriver = strdup(mgo.opt); break;
- case 's': free(sounddriver); sounddriver = strdup(mgo.opt); break;
- case 'v': free(videodriver); videodriver = strdup(mgo.opt); break;
- case 'b': free(blitter); blitter = strdup(mgo.opt); break;
+ case 'I': free(graphics_set); graphics_set = stredup(mgo.opt); break;
+ case 'S': free(sounds_set); sounds_set = stredup(mgo.opt); break;
+ case 'M': free(music_set); music_set = stredup(mgo.opt); break;
+ case 'm': free(musicdriver); musicdriver = stredup(mgo.opt); break;
+ case 's': free(sounddriver); sounddriver = stredup(mgo.opt); break;
+ case 'v': free(videodriver); videodriver = stredup(mgo.opt); break;
+ case 'b': free(blitter); blitter = stredup(mgo.opt); break;
#if defined(ENABLE_NETWORK)
case 'D':
free(musicdriver);
free(sounddriver);
free(videodriver);
free(blitter);
- musicdriver = strdup("null");
- sounddriver = strdup("null");
- videodriver = strdup("dedicated");
- blitter = strdup("null");
+ musicdriver = stredup("null");
+ sounddriver = stredup("null");
+ videodriver = stredup("dedicated");
+ blitter = stredup("null");
dedicated = true;
SetDebugString("net=6");
if (mgo.opt != NULL) {
@@ -667,7 +667,7 @@ int openttd_main(int argc, char *argv[])
goto exit_noshutdown;
}
case 'G': scanner->generation_seed = atoi(mgo.opt); break;
- case 'c': _config_file = strdup(mgo.opt); break;
+ case 'c': _config_file = stredup(mgo.opt); break;
case 'x': scanner->save_config = false; break;
case 'h':
i = -2; // Force printing of help.
@@ -739,7 +739,7 @@ int openttd_main(int argc, char *argv[])
InitWindowSystem();
BaseGraphics::FindSets();
- if (graphics_set == NULL && BaseGraphics::ini_set != NULL) graphics_set = strdup(BaseGraphics::ini_set);
+ if (graphics_set == NULL && BaseGraphics::ini_set != NULL) graphics_set = stredup(BaseGraphics::ini_set);
if (!BaseGraphics::SetSet(graphics_set)) {
if (!StrEmpty(graphics_set)) {
BaseGraphics::SetSet(NULL);
@@ -755,7 +755,7 @@ int openttd_main(int argc, char *argv[])
GfxInitPalettes();
DEBUG(misc, 1, "Loading blitter...");
- if (blitter == NULL && _ini_blitter != NULL) blitter = strdup(_ini_blitter);
+ if (blitter == NULL && _ini_blitter != NULL) blitter = stredup(_ini_blitter);
_blitter_autodetected = StrEmpty(blitter);
/* If we have a 32 bpp base set, try to select the 32 bpp blitter first, but only if we autoprobe the blitter. */
if (!_blitter_autodetected || BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP || BlitterFactory::SelectBlitter("32bpp-anim") == NULL) {
@@ -767,7 +767,7 @@ int openttd_main(int argc, char *argv[])
}
free(blitter);
- if (videodriver == NULL && _ini_videodriver != NULL) videodriver = strdup(_ini_videodriver);
+ if (videodriver == NULL && _ini_videodriver != NULL) videodriver = stredup(_ini_videodriver);
_video_driver = (VideoDriver*)DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
if (_video_driver == NULL) {
StrEmpty(videodriver) ?
@@ -810,7 +810,7 @@ int openttd_main(int argc, char *argv[])
InitializeScreenshotFormats();
BaseSounds::FindSets();
- if (sounds_set == NULL && BaseSounds::ini_set != NULL) sounds_set = strdup(BaseSounds::ini_set);
+ if (sounds_set == NULL && BaseSounds::ini_set != NULL) sounds_set = stredup(BaseSounds::ini_set);
if (!BaseSounds::SetSet(sounds_set)) {
if (StrEmpty(sounds_set) || !BaseSounds::SetSet(NULL)) {
usererror("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 4.1 of readme.txt.");
@@ -823,7 +823,7 @@ int openttd_main(int argc, char *argv[])
free(sounds_set);
BaseMusic::FindSets();
- if (music_set == NULL && BaseMusic::ini_set != NULL) music_set = strdup(BaseMusic::ini_set);
+ if (music_set == NULL && BaseMusic::ini_set != NULL) music_set = stredup(BaseMusic::ini_set);
if (!BaseMusic::SetSet(music_set)) {
if (StrEmpty(music_set) || !BaseMusic::SetSet(NULL)) {
usererror("Failed to find a music set. Please acquire a music set for OpenTTD. See section 4.1 of readme.txt.");
@@ -835,7 +835,7 @@ int openttd_main(int argc, char *argv[])
}
free(music_set);
- if (sounddriver == NULL && _ini_sounddriver != NULL) sounddriver = strdup(_ini_sounddriver);
+ if (sounddriver == NULL && _ini_sounddriver != NULL) sounddriver = stredup(_ini_sounddriver);
_sound_driver = (SoundDriver*)DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
if (_sound_driver == NULL) {
StrEmpty(sounddriver) ?
@@ -844,7 +844,7 @@ int openttd_main(int argc, char *argv[])
}
free(sounddriver);
- if (musicdriver == NULL && _ini_musicdriver != NULL) musicdriver = strdup(_ini_musicdriver);
+ if (musicdriver == NULL && _ini_musicdriver != NULL) musicdriver = stredup(_ini_musicdriver);
_music_driver = (MusicDriver*)DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
if (_music_driver == NULL) {
StrEmpty(musicdriver) ?
@@ -1157,7 +1157,7 @@ void SwitchToMode(SwitchMode new_mode)
LoadIntroGame();
if (BaseSounds::ini_set == NULL && BaseSounds::GetUsedSet()->fallback) {
ShowErrorMessage(STR_WARNING_FALLBACK_SOUNDSET, INVALID_STRING_ID, WL_CRITICAL);
- BaseSounds::ini_set = strdup(BaseSounds::GetUsedSet()->name);
+ BaseSounds::ini_set = stredup(BaseSounds::GetUsedSet()->name);
}
break;
diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp
index 011c8e53c..bac1416e4 100644
--- a/src/os/windows/win32.cpp
+++ b/src/os/windows/win32.cpp
@@ -435,7 +435,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
/* Convert the command line to UTF-8. We need a dedicated buffer
* for this because argv[] points into this buffer and this needs to
* be available between subsequent calls to FS2OTTD(). */
- char *cmdline = strdup(FS2OTTD(GetCommandLine()));
+ char *cmdline = stredup(FS2OTTD(GetCommandLine()));
#if defined(_DEBUG)
CreateConsole();
@@ -498,7 +498,7 @@ void DetermineBasePaths(const char *exe)
AppendPathSeparator(tmp, lastof(tmp));
strecat(tmp, PERSONAL_DIR, lastof(tmp));
AppendPathSeparator(tmp, lastof(tmp));
- _searchpaths[SP_PERSONAL_DIR] = strdup(tmp);
+ _searchpaths[SP_PERSONAL_DIR] = stredup(tmp);
} else {
_searchpaths[SP_PERSONAL_DIR] = NULL;
}
@@ -508,7 +508,7 @@ void DetermineBasePaths(const char *exe)
AppendPathSeparator(tmp, lastof(tmp));
strecat(tmp, PERSONAL_DIR, lastof(tmp));
AppendPathSeparator(tmp, lastof(tmp));
- _searchpaths[SP_SHARED_DIR] = strdup(tmp);
+ _searchpaths[SP_SHARED_DIR] = stredup(tmp);
} else {
_searchpaths[SP_SHARED_DIR] = NULL;
}
@@ -520,7 +520,7 @@ void DetermineBasePaths(const char *exe)
/* Get the path to working directory of OpenTTD */
getcwd(tmp, lengthof(tmp));
AppendPathSeparator(tmp, lastof(tmp));
- _searchpaths[SP_WORKING_DIR] = strdup(tmp);
+ _searchpaths[SP_WORKING_DIR] = stredup(tmp);
if (!GetModuleFileName(NULL, path, lengthof(path))) {
DEBUG(misc, 0, "GetModuleFileName failed (%lu)\n", GetLastError());
@@ -535,7 +535,7 @@ void DetermineBasePaths(const char *exe)
strecpy(tmp, convert_from_fs(exec_dir, tmp, lengthof(tmp)), lastof(tmp));
char *s = strrchr(tmp, PATHSEPCHAR);
*(s + 1) = '\0';
- _searchpaths[SP_BINARY_DIR] = strdup(tmp);
+ _searchpaths[SP_BINARY_DIR] = stredup(tmp);
}
}
diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp
index 446f88db6..52ef5ebb9 100644
--- a/src/osk_gui.cpp
+++ b/src/osk_gui.cpp
@@ -59,7 +59,7 @@ struct OskWindow : public Window {
this->querystrings[WID_OSK_TEXT] = this->qs;
/* make a copy in case we need to reset later */
- this->orig_str_buf = strdup(this->qs->text.buf);
+ this->orig_str_buf = stredup(this->qs->text.buf);
this->InitNested(0);
this->SetFocusedWidget(WID_OSK_TEXT);
@@ -430,7 +430,7 @@ void UpdateOSKOriginalText(const Window *parent, int button)
if (osk == NULL || osk->parent != parent || osk->text_btn != button) return;
free(osk->orig_str_buf);
- osk->orig_str_buf = strdup(osk->qs->text.buf);
+ osk->orig_str_buf = stredup(osk->qs->text.buf);
osk->SetDirty();
}
diff --git a/src/safeguards.h b/src/safeguards.h
index 1107ba6f2..d2b388721 100644
--- a/src/safeguards.h
+++ b/src/safeguards.h
@@ -31,11 +31,11 @@
#define realloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
/* Use stredup instead. */
-//#define strdup SAFEGUARD_DO_NOT_USE_THIS_METHOD
+#define strdup SAFEGUARD_DO_NOT_USE_THIS_METHOD
#define strndup SAFEGUARD_DO_NOT_USE_THIS_METHOD
/* Use strecpy instead. */
-//#define strcpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
+#define strcpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
//#define strncpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
/* Use strecat instead. */
diff --git a/src/saveload/engine_sl.cpp b/src/saveload/engine_sl.cpp
index 80ab5debd..07bad4606 100644
--- a/src/saveload/engine_sl.cpp
+++ b/src/saveload/engine_sl.cpp
@@ -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 */
diff --git a/src/saveload/game_sl.cpp b/src/saveload/game_sl.cpp
index 141353d81..a3273114c 100644
--- a/src/saveload/game_sl.cpp
+++ b/src/saveload/game_sl.cpp
@@ -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;
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 707c85510..647423ada 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -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
diff --git a/src/saveload/strings_sl.cpp b/src/saveload/strings_sl.cpp
index c6b63bc1a..73f2a1e2e 100644
--- a/src/saveload/strings_sl.cpp
+++ b/src/saveload/strings_sl.cpp
@@ -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)]);
}
}
diff --git a/src/script/api/script_controller.cpp b/src/script/api/script_controller.cpp
index 4c3a5cd6e..65e542c02 100644
--- a/src/script/api/script_controller.cpp
+++ b/src/script/api/script_controller.cpp
@@ -154,7 +154,7 @@ ScriptController::~ScriptController()
sq_newslot(vm, -3, SQFalse);
sq_pop(vm, 1);
- controller->loaded_library[strdup(library_name)] = strdup(fake_class);
+ controller->loaded_library[stredup(library_name)] = stredup(fake_class);
}
/* Find the real class inside the fake class (like 'sets.Vector') */
diff --git a/src/script/api/script_error.cpp b/src/script/api/script_error.cpp
index 9dd6ece19..d30ad9c66 100644
--- a/src/script/api/script_error.cpp
+++ b/src/script/api/script_error.cpp
@@ -12,6 +12,7 @@
#include "../../stdafx.h"
#include "script_error.hpp"
#include "../../core/bitmath_func.hpp"
+#include "../../string_func.h"
#include "../../safeguards.h"
@@ -25,7 +26,7 @@ ScriptError::ScriptErrorMapString ScriptError::error_map_string = ScriptError::S
/* static */ char *ScriptError::GetLastErrorString()
{
- return strdup((*error_map_string.find(ScriptError::GetLastError())).second);
+ return stredup((*error_map_string.find(ScriptError::GetLastError())).second);
}
/* static */ ScriptErrorType ScriptError::StringToError(StringID internal_string_id)
diff --git a/src/script/api/script_event_types.cpp b/src/script/api/script_event_types.cpp
index 8c1395c11..277ce22ec 100644
--- a/src/script/api/script_event_types.cpp
+++ b/src/script/api/script_event_types.cpp
@@ -17,6 +17,7 @@
#include "../../settings_type.h"
#include "../../engine_base.h"
#include "../../articulated_vehicles.h"
+#include "../../string_func.h"
#include "table/strings.h"
#include "../../safeguards.h"
@@ -119,6 +120,17 @@ bool ScriptEventCompanyAskMerger::AcceptMerger()
return ScriptObject::DoCommand(0, this->owner, 0, CMD_BUY_COMPANY);
}
+ScriptEventAdminPort::ScriptEventAdminPort(const char *json) :
+ ScriptEvent(ET_ADMIN_PORT),
+ json(stredup(json))
+{
+}
+
+ScriptEventAdminPort::~ScriptEventAdminPort()
+{
+ free(this->json);
+}
+
#define SKIP_EMPTY(p) while (*(p) == ' ' || *(p) == '\n' || *(p) == '\r') (p)++;
#define RETURN_ERROR(stack) { ScriptLog::Error("Received invalid JSON data from AdminPort."); if (stack != 0) sq_pop(vm, stack); return NULL; }
diff --git a/src/script/api/script_event_types.hpp b/src/script/api/script_event_types.hpp
index 62834113d..943016897 100644
--- a/src/script/api/script_event_types.hpp
+++ b/src/script/api/script_event_types.hpp
@@ -839,15 +839,8 @@ public:
/**
* @param json The JSON string which got sent.
*/
- ScriptEventAdminPort(const char *json) :
- ScriptEvent(ET_ADMIN_PORT),
- json(strdup(json))
- {}
-
- ~ScriptEventAdminPort()
- {
- free(this->json);
- }
+ ScriptEventAdminPort(const char *json);
+ ~ScriptEventAdminPort();
/**
* Convert an ScriptEvent to the real instance.
diff --git a/src/script/api/script_log.cpp b/src/script/api/script_log.cpp
index 6e725617c..d9fbbde98 100644
--- a/src/script/api/script_log.cpp
+++ b/src/script/api/script_log.cpp
@@ -14,6 +14,7 @@
#include "../../core/alloc_func.hpp"
#include "../../debug.h"
#include "../../window_func.h"
+#include "../../string_func.h"
#include "../../safeguards.h"
@@ -53,7 +54,7 @@
/* Free last message, and write new message */
free(log->lines[log->pos]);
- log->lines[log->pos] = strdup(message);
+ log->lines[log->pos] = stredup(message);
log->type[log->pos] = level;
/* Cut string after first \n */
diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp
index 47de2b1a7..49dba6bb7 100644
--- a/src/script/api/script_object.cpp
+++ b/src/script/api/script_object.cpp
@@ -264,7 +264,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
char buffer[64];
::GetString(buffer, string, lastof(buffer));
::str_validate(buffer, lastof(buffer), SVS_NONE);
- return ::strdup(buffer);
+ return ::stredup(buffer);
}
/* static */ void ScriptObject::SetCallbackVariable(int index, int value)
diff --git a/src/script/api/script_text.cpp b/src/script/api/script_text.cpp
index 9fb297990..1529d4577 100644
--- a/src/script/api/script_text.cpp
+++ b/src/script/api/script_text.cpp
@@ -19,6 +19,16 @@
#include "../../safeguards.h"
+RawText::RawText(const char *text) : text(stredup(text))
+{
+}
+
+RawText::~RawText()
+{
+ free(this->text);
+}
+
+
ScriptText::ScriptText(HSQUIRRELVM vm) :
ZeroedMemoryAllocator()
{
@@ -73,7 +83,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm)
const SQChar *value;
sq_getstring(vm, -1, &value);
- this->params[parameter] = strdup(SQ2OTTD(value));
+ this->params[parameter] = stredup(SQ2OTTD(value));
ValidateString(this->params[parameter]);
break;
}
diff --git a/src/script/api/script_text.hpp b/src/script/api/script_text.hpp
index 9b75e21c5..fe38be197 100644
--- a/src/script/api/script_text.hpp
+++ b/src/script/api/script_text.hpp
@@ -42,9 +42,8 @@ public:
*/
class RawText : public Text {
public:
- RawText(const char *text) :
- text(strdup(text)) {}
- ~RawText() { free(this->text); }
+ RawText(const char *text);
+ ~RawText();
/* virtual */ const char *GetEncodedText() { return this->text; }
private:
diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp
index 768ff5e21..a6e41476e 100644
--- a/src/script/script_config.cpp
+++ b/src/script/script_config.cpp
@@ -21,7 +21,7 @@
void ScriptConfig::Change(const char *name, int version, bool force_exact_match, bool is_random)
{
free(this->name);
- this->name = (name == NULL) ? NULL : strdup(name);
+ this->name = (name == NULL) ? NULL : stredup(name);
this->info = (name == NULL) ? NULL : this->FindInfo(this->name, version, force_exact_match);
this->version = (info == NULL) ? -1 : info->GetVersion();
this->is_random = is_random;
@@ -45,14 +45,14 @@ void ScriptConfig::Change(const char *name, int version, bool force_exact_match,
ScriptConfig::ScriptConfig(const ScriptConfig *config)
{
- this->name = (config->name == NULL) ? NULL : strdup(config->name);
+ this->name = (config->name == NULL) ? NULL : stredup(config->name);
this->info = config->info;
this->version = config->version;
this->config_list = NULL;
this->is_random = config->is_random;
for (SettingValueList::const_iterator it = config->settings.begin(); it != config->settings.end(); it++) {
- this->settings[strdup((*it).first)] = (*it).second;
+ this->settings[stredup((*it).first)] = (*it).second;
}
this->AddRandomDeviation();
}
@@ -117,7 +117,7 @@ void ScriptConfig::SetSetting(const char *name, int value)
if (it != this->settings.end()) {
(*it).second = value;
} else {
- this->settings[strdup(name)] = value;
+ this->settings[stredup(name)] = value;
}
}
@@ -160,7 +160,7 @@ int ScriptConfig::GetVersion() const
void ScriptConfig::StringToSettings(const char *value)
{
- char *value_copy = strdup(value);
+ char *value_copy = stredup(value);
char *s = value_copy;
while (s != NULL) {
diff --git a/src/script/script_info.cpp b/src/script/script_info.cpp
index 27bcec1eb..83d3bab8a 100644
--- a/src/script/script_info.cpp
+++ b/src/script/script_info.cpp
@@ -83,9 +83,9 @@ bool ScriptInfo::CheckMethod(const char *name) const
}
/* Get location information of the scanner */
- info->main_script = strdup(info->scanner->GetMainScript());
+ info->main_script = stredup(info->scanner->GetMainScript());
const char *tar_name = info->scanner->GetTarFile();
- if (tar_name != NULL) info->tar_file = strdup(tar_name);
+ if (tar_name != NULL) info->tar_file = stredup(tar_name);
/* Cache the data the info file gives us. */
if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAuthor", &info->author, MAX_GET_OPS)) return SQ_ERROR;
@@ -133,7 +133,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
if (strcmp(key, "name") == 0) {
const SQChar *sqvalue;
if (SQ_FAILED(sq_getstring(vm, -1, &sqvalue))) return SQ_ERROR;
- char *name = strdup(SQ2OTTD(sqvalue));
+ char *name = stredup(SQ2OTTD(sqvalue));
char *s;
ValidateString(name);
@@ -146,7 +146,7 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
} else if (strcmp(key, "description") == 0) {
const SQChar *sqdescription;
if (SQ_FAILED(sq_getstring(vm, -1, &sqdescription))) return SQ_ERROR;
- config.description = strdup(SQ2OTTD(sqdescription));
+ config.description = stredup(SQ2OTTD(sqdescription));
ValidateString(config.description);
items |= 0x002;
} else if (strcmp(key, "min_value") == 0) {
@@ -264,8 +264,8 @@ SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
const char *label = SQ2OTTD(sq_label);
ValidateString(label);
- /* !Contains() prevents strdup from leaking. */
- if (!config->labels->Contains(key)) config->labels->Insert(key, strdup(label));
+ /* !Contains() prevents stredup from leaking. */
+ if (!config->labels->Contains(key)) config->labels->Insert(key, stredup(label));
sq_pop(vm, 2);
}
diff --git a/src/script/script_scanner.cpp b/src/script/script_scanner.cpp
index 3796aafd5..98bc1f385 100644
--- a/src/script/script_scanner.cpp
+++ b/src/script/script_scanner.cpp
@@ -29,12 +29,12 @@
bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
{
free(this->main_script);
- this->main_script = strdup(filename);
+ this->main_script = stredup(filename);
if (this->main_script == NULL) return false;
free(this->tar_file);
if (tar_filename != NULL) {
- this->tar_file = strdup(tar_filename);
+ this->tar_file = stredup(tar_filename);
if (this->tar_file == NULL) return false;
} else {
this->tar_file = NULL;
@@ -150,13 +150,13 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
return;
}
- this->info_list[strdup(script_name)] = info;
+ this->info_list[stredup(script_name)] = info;
if (!info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) {
/* Add the script to the 'unique' script list, where only the highest version
* of the script is registered. */
if (this->info_single_list.find(script_original_name) == this->info_single_list.end()) {
- this->info_single_list[strdup(script_original_name)] = info;
+ this->info_single_list[stredup(script_original_name)] = info;
} else if (this->info_single_list[script_original_name]->GetVersion() < info->GetVersion()) {
this->info_single_list[script_original_name] = info;
}
diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp
index 99e5ae1c0..aa25166b7 100644
--- a/src/script/squirrel.cpp
+++ b/src/script/squirrel.cpp
@@ -260,7 +260,7 @@ bool Squirrel::CallStringMethodStrdup(HSQOBJECT instance, const char *method_nam
HSQOBJECT ret;
if (!this->CallMethod(instance, method_name, &ret, suspend)) return false;
if (ret._type != OT_STRING) return false;
- *res = strdup(ObjectToString(&ret));
+ *res = stredup(ObjectToString(&ret));
ValidateString(*res);
return true;
}
diff --git a/src/script/squirrel_helper.hpp b/src/script/squirrel_helper.hpp
index 3e3764384..ff00712c0 100644
--- a/src/script/squirrel_helper.hpp
+++ b/src/script/squirrel_helper.hpp
@@ -26,7 +26,7 @@ template <class CL, ScriptType ST> const char *GetClassName();
namespace SQConvert {
/**
* Pointers assigned to this class will be free'd when this instance
- * comes out of scope. Useful to make sure you can use strdup(),
+ * comes out of scope. Useful to make sure you can use stredup(),
* without leaking memory.
*/
struct SQAutoFreePointers : SmallVector<void *, 1> {
@@ -113,7 +113,7 @@ namespace SQConvert {
const SQChar *tmp;
sq_getstring(vm, -1, &tmp);
- char *tmp_str = strdup(SQ2OTTD(tmp));
+ char *tmp_str = stredup(SQ2OTTD(tmp));
sq_poptop(vm);
*ptr->Append() = (void *)tmp_str;
str_validate(tmp_str, tmp_str + strlen(tmp_str));
diff --git a/src/script/squirrel_std.cpp b/src/script/squirrel_std.cpp
index f09471554..0fb8564c8 100644
--- a/src/script/squirrel_std.cpp
+++ b/src/script/squirrel_std.cpp
@@ -16,11 +16,13 @@
#include "squirrel_std.hpp"
#include "../core/alloc_func.hpp"
#include "../core/math_func.hpp"
+#include "../string_func.h"
/* Due to the different characters for Squirrel, the scstrcat might be a simple
* strcat which triggers the safeguard. But it isn't always a simple strcat. */
#include "../safeguards.h"
#undef strcat
+#undef strdup
SQInteger SquirrelStd::min(HSQUIRRELVM vm)
@@ -71,7 +73,7 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm)
real_filename = ReallocT(real_filename, scstrlen(real_filename) + scstrlen(filename) + 1);
scstrcat(real_filename, filename);
/* Tars dislike opening files with '/' on Windows.. so convert it to '\\' ;) */
- char *filen = strdup(SQ2OTTD(real_filename));
+ char *filen = stredup(SQ2OTTD(real_filename));
#if (PATHSEPCHAR != '/')
for (char *n = filen; *n != '\0'; n++) if (*n == '/') *n = PATHSEPCHAR;
#endif
diff --git a/src/settings.cpp b/src/settings.cpp
index a5de03d21..11f30c150 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -532,7 +532,7 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
case SLE_VAR_STR:
case SLE_VAR_STRQ:
free(*(char**)ptr);
- *(char**)ptr = p == NULL ? NULL : strdup((const char*)p);
+ *(char**)ptr = p == NULL ? NULL : stredup((const char*)p);
break;
case SLE_VAR_CHAR: if (p != NULL) *(char *)ptr = *(const char *)p; break;
@@ -687,7 +687,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
/* The value is different, that means we have to write it to the ini */
free(item->value);
- item->value = strdup(buf);
+ item->value = stredup(buf);
}
}
@@ -709,7 +709,7 @@ static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList *li
list->Clear();
for (const IniItem *item = group->item; item != NULL; item = item->next) {
- if (item->name != NULL) *list->Append() = strdup(item->name);
+ if (item->name != NULL) *list->Append() = stredup(item->name);
}
}
@@ -1659,7 +1659,7 @@ void GetGRFPresetList(GRFPresetList *list)
IniGroup *group;
for (group = ini->group; group != NULL; group = group->next) {
if (strncmp(group->name, "preset-", 7) == 0) {
- *list->Append() = strdup(group->name + 7);
+ *list->Append() = stredup(group->name + 7);
}
}
@@ -1929,7 +1929,7 @@ bool SetSettingValue(uint index, const char *value, bool force_newgame)
if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) {
char **var = (char**)GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
free(*var);
- *var = strcmp(value, "(null)") == 0 ? NULL : strdup(value);
+ *var = strcmp(value, "(null)") == 0 ? NULL : stredup(value);
} else {
char *var = (char*)GetVariableAddress(NULL, &sd->save);
strecpy(var, value, &var[sd->save.length - 1]);
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index ea8c93feb..fc3360a59 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -460,7 +460,7 @@ struct GameOptionsWindow : Window {
const char *name = T::GetSet(index)->name;
free(T::ini_set);
- T::ini_set = strdup(name);
+ T::ini_set = stredup(name);
T::SetSet(name);
this->reload = true;
diff --git a/src/signs_cmd.cpp b/src/signs_cmd.cpp
index 9a21c4e35..4badd3605 100644
--- a/src/signs_cmd.cpp
+++ b/src/signs_cmd.cpp
@@ -55,7 +55,7 @@ CommandCost CmdPlaceSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
si->y = y;
si->z = GetSlopePixelZ(x, y);
if (!StrEmpty(text)) {
- si->name = strdup(text);
+ si->name = stredup(text);
}
si->UpdateVirtCoord();
InvalidateWindowData(WC_SIGN_LIST, 0, 0);
@@ -90,7 +90,7 @@ CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Delete the old name */
free(si->name);
/* Assign the new one */
- si->name = strdup(text);
+ si->name = stredup(text);
if (_game_mode != GM_EDITOR) si->owner = _current_company;
si->UpdateVirtCoord();
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 9c2ddc181..56c79a1ad 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -3727,7 +3727,7 @@ CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (flags & DC_EXEC) {
free(st->name);
- st->name = reset ? NULL : strdup(text);
+ st->name = reset ? NULL : stredup(text);
st->UpdateVirtCoord();
InvalidateWindowData(WC_STATION_LIST, st->owner, 1);
diff --git a/src/stdafx.h b/src/stdafx.h
index 7d7e1990b..d0e6fb30a 100644
--- a/src/stdafx.h
+++ b/src/stdafx.h
@@ -281,7 +281,7 @@
#endif
#if defined(WINCE)
- #define strdup _strdup
+ #define stredup _stredup
#endif /* WINCE */
/* NOTE: the string returned by these functions is only valid until the next
diff --git a/src/story.cpp b/src/story.cpp
index 46a193631..b74842f41 100644
--- a/src/story.cpp
+++ b/src/story.cpp
@@ -81,10 +81,10 @@ static void UpdateElement(StoryPageElement &pe, TileIndex tile, uint32 reference
{
switch (pe.type) {
case SPET_TEXT:
- pe.text = strdup(text);
+ pe.text = stredup(text);
break;
case SPET_LOCATION:
- pe.text = strdup(text);
+ pe.text = stredup(text);
pe.referenced_id = tile;
break;
case SPET_GOAL:
@@ -126,7 +126,7 @@ CommandCost CmdCreateStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (StrEmpty(text)) {
s->title = NULL;
} else {
- s->title = strdup(text);
+ s->title = stredup(text);
}
InvalidateWindowClassesData(WC_STORY_BOOK, -1);
@@ -243,7 +243,7 @@ CommandCost CmdSetStoryPageTitle(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (StrEmpty(text)) {
p->title = NULL;
} else {
- p->title = strdup(text);
+ p->title = stredup(text);
}
InvalidateWindowClassesData(WC_STORY_BOOK, page_id);
diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp
index 4cd2454f4..7769ca242 100644
--- a/src/strgen/strgen.cpp
+++ b/src/strgen/strgen.cpp
@@ -247,7 +247,7 @@ struct FileWriter {
*/
FileWriter(const char *filename)
{
- this->filename = strdup(filename);
+ this->filename = stredup(filename);
this->fh = fopen(this->filename, "wb");
if (this->fh == NULL) {
@@ -285,7 +285,7 @@ struct HeaderFileWriter : HeaderWriter, FileWriter {
* @param filename The file to open.
*/
HeaderFileWriter(const char *filename) : FileWriter("tmp.xxx"),
- real_filename(strdup(filename)), prev(0)
+ real_filename(stredup(filename)), prev(0)
{
fprintf(this->fh, "/* This file is automatically generated. Do not modify */\n\n");
fprintf(this->fh, "#ifndef TABLE_STRINGS_H\n");
diff --git a/src/strgen/strgen_base.cpp b/src/strgen/strgen_base.cpp
index 27c76631c..ef30a4c8a 100644
--- a/src/strgen/strgen_base.cpp
+++ b/src/strgen/strgen_base.cpp
@@ -40,7 +40,7 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
* @param next The next chained case.
*/
Case::Case(int caseidx, const char *string, Case *next) :
- caseidx(caseidx), string(strdup(string)), next(next)
+ caseidx(caseidx), string(stredup(string)), next(next)
{
}
@@ -59,7 +59,7 @@ Case::~Case()
* @param line The line this string was found on.
*/
LangString::LangString(const char *name, const char *english, int index, int line) :
- name(strdup(name)), english(strdup(english)), translated(NULL),
+ name(stredup(name)), english(stredup(english)), translated(NULL),
hash_next(0), index(index), line(line), translated_case(NULL)
{
}
@@ -577,7 +577,7 @@ static const CmdStruct *ParseCommandString(const char **str, char *param, int *a
* @param translation Are we reading a translation?
*/
StringReader::StringReader(StringData &data, const char *file, bool master, bool translation) :
- data(data), file(strdup(file)), master(master), translation(translation)
+ data(data), file(stredup(file)), master(master), translation(translation)
{
}
@@ -614,7 +614,7 @@ static void ExtractCommandString(ParsedCommandStruct *p, const char *s, bool war
} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them
if (p->np >= lengthof(p->pairs)) strgen_fatal("too many commands in string, max " PRINTF_SIZE, lengthof(p->pairs));
p->pairs[p->np].a = ar;
- p->pairs[p->np].v = param[0] != '\0' ? strdup(param) : "";
+ p->pairs[p->np].v = param[0] != '\0' ? stredup(param) : "";
p->np++;
}
}
@@ -778,7 +778,7 @@ void StringReader::HandleString(char *str)
if (casep != NULL) {
ent->translated_case = new Case(ResolveCaseName(casep, strlen(casep)), s, ent->translated_case);
} else {
- ent->translated = strdup(s);
+ ent->translated = stredup(s);
/* If the string was translated, use the line from the
* translated language so errors in the translated file
* are properly referenced to. */
diff --git a/src/strings.cpp b/src/strings.cpp
index 1b95f4251..e69c6cf1c 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -165,7 +165,7 @@ void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num)
MemCpyT(dst, _global_string_params.GetPointerToOffset(0), num);
for (int i = 0; i < num; i++) {
if (_global_string_params.HasTypeInformation() && _global_string_params.GetTypeAtOffset(i) == SCC_RAW_STRING_POINTER) {
- strings[i] = strdup((const char *)(size_t)_global_string_params.GetParam(i));
+ strings[i] = stredup((const char *)(size_t)_global_string_params.GetParam(i));
dst[i] = (size_t)strings[i];
} else {
strings[i] = NULL;
@@ -889,7 +889,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
sub_args.SetParam(i++, param);
} else {
- char *g = strdup(s);
+ char *g = stredup(s);
g[p - s] = '\0';
sub_args_need_free[i] = true;
@@ -2124,7 +2124,7 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
* properly we have to set the colour of the string, otherwise we end up with a lot of artifacts.
* The colour 'character' might change in the future, so for safety we just Utf8 Encode it into
* the string, which takes exactly three characters, so it replaces the "XXX" with the colour marker. */
- static char *err_str = strdup("XXXThe current font is missing some of the characters used in the texts for this language. Read the readme to see how to solve this.");
+ static char *err_str = stredup("XXXThe current font is missing some of the characters used in the texts for this language. Read the readme to see how to solve this.");
Utf8Encode(err_str, SCC_YELLOW);
SetDParamStr(0, err_str);
ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_WARNING);
@@ -2152,7 +2152,7 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
* the colour marker.
*/
if (_current_text_dir != TD_LTR) {
- static char *err_str = strdup("XXXThis version of OpenTTD does not support right-to-left languages. Recompile with icu enabled.");
+ static char *err_str = stredup("XXXThis version of OpenTTD does not support right-to-left languages. Recompile with icu enabled.");
Utf8Encode(err_str, SCC_YELLOW);
SetDParamStr(0, err_str);
ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
diff --git a/src/subsidy.cpp b/src/subsidy.cpp
index 974aa50a8..62b463ced 100644
--- a/src/subsidy.cpp
+++ b/src/subsidy.cpp
@@ -24,6 +24,7 @@
#include "core/random_func.hpp"
#include "game/game.hpp"
#include "command_func.h"
+#include "string_func.h"
#include "table/strings.h"
@@ -47,7 +48,7 @@ void Subsidy::AwardTo(CompanyID company)
SetDParam(0, company);
GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
- char *cn = strdup(company_name);
+ char *cn = stredup(company_name);
/* Add a news item */
Pair reftype = SetupSubsidyDecodeParam(this, false);
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 78d453ed3..1c6a01eae 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1705,7 +1705,7 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
old_generating_world.Restore();
if (t != NULL && !StrEmpty(text)) {
- t->name = strdup(text);
+ t->name = stredup(text);
t->UpdateVirtCoord();
}
@@ -1716,7 +1716,7 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
SetDParam(0, _current_company);
GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
- char *cn = strdup(company_name);
+ char *cn = stredup(company_name);
SetDParamStr(0, cn);
SetDParam(1, t->index);
@@ -2448,7 +2448,7 @@ CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (flags & DC_EXEC) {
free(t->name);
- t->name = reset ? NULL : strdup(text);
+ t->name = reset ? NULL : stredup(text);
t->UpdateVirtCoord();
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1);
@@ -2525,7 +2525,7 @@ CommandCost CmdTownSetText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (flags & DC_EXEC) {
free(t->text);
- t->text = StrEmpty(text) ? NULL : strdup(text);
+ t->text = StrEmpty(text) ? NULL : stredup(text);
InvalidateWindowData(WC_TOWN_VIEW, p1);
}
@@ -2742,7 +2742,7 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags)
SetDParam(0, _current_company);
GetString(company_name, STR_COMPANY_NAME, lastof(company_name));
- char *cn = strdup(company_name);
+ char *cn = stredup(company_name);
SetDParam(0, t->index);
SetDParamStr(1, cn);
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index c42eb338f..72cff271a 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -751,7 +751,7 @@ static void CloneVehicleName(const Vehicle *src, Vehicle *dst)
/* Check the name is unique. */
if (IsUniqueVehicleName(buf)) {
- dst->name = strdup(buf);
+ dst->name = stredup(buf);
break;
}
}
@@ -1029,7 +1029,7 @@ CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (flags & DC_EXEC) {
free(v->name);
- v->name = reset ? NULL : strdup(text);
+ v->name = reset ? NULL : stredup(text);
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 1);
MarkWholeScreenDirty();
}
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index cbd7acd07..d87fa10b2 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -622,7 +622,7 @@ void cocoaSetApplicationBundleDir()
CFURLRef url = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
if (CFURLGetFileSystemRepresentation(url, true, (unsigned char*)tmp, MAXPATHLEN)) {
AppendPathSeparator(tmp, lastof(tmp));
- _searchpaths[SP_APPLICATION_BUNDLE_DIR] = strdup(tmp);
+ _searchpaths[SP_APPLICATION_BUNDLE_DIR] = stredup(tmp);
} else {
_searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL;
}
diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp
index b2656987d..3c2701270 100644
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -416,7 +416,7 @@ CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
if (flags & DC_EXEC) {
free(wp->name);
- wp->name = reset ? NULL : strdup(text);
+ wp->name = reset ? NULL : stredup(text);
wp->UpdateVirtCoord();
}