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