diff options
author | rubidium <rubidium@openttd.org> | 2014-04-25 15:40:32 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2014-04-25 15:40:32 +0000 |
commit | 9ed12b0f07edb342aaff21c130d325fd158a9d5b (patch) | |
tree | f42aa775396b4ebda4d119f76e80a77c180936c7 /src/script/api | |
parent | 4227f495c51ea909707505ec2ef1c730a382965d (diff) | |
download | openttd-9ed12b0f07edb342aaff21c130d325fd158a9d5b.tar.xz |
(svn r26509) -Codechange: replace strdup with stredup (the latter ensures the return is not NULL)
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/script_controller.cpp | 2 | ||||
-rw-r--r-- | src/script/api/script_error.cpp | 3 | ||||
-rw-r--r-- | src/script/api/script_event_types.cpp | 12 | ||||
-rw-r--r-- | src/script/api/script_event_types.hpp | 11 | ||||
-rw-r--r-- | src/script/api/script_log.cpp | 3 | ||||
-rw-r--r-- | src/script/api/script_object.cpp | 2 | ||||
-rw-r--r-- | src/script/api/script_text.cpp | 12 | ||||
-rw-r--r-- | src/script/api/script_text.hpp | 5 |
8 files changed, 33 insertions, 17 deletions
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: |