(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:
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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));
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user