summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/newgrf.cpp20
-rw-r--r--src/newgrf_config.cpp12
-rw-r--r--src/newgrf_config.h13
-rw-r--r--src/newgrf_gui.cpp12
4 files changed, 24 insertions, 33 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 3f621e5c9..6b5a2f9ce 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -5248,7 +5248,7 @@ static void NewSpriteGroup(ByteReader *buf)
group->num_input = buf->ReadByte();
if (group->num_input > lengthof(group->subtract_input)) {
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_INDPROD_CALLBACK);
- error->data = stredup("too many inputs (max 16)");
+ error->data = "too many inputs (max 16)";
return;
}
for (uint i = 0; i < group->num_input; i++) {
@@ -5261,7 +5261,7 @@ static void NewSpriteGroup(ByteReader *buf)
group->version = 0xFF;
} else if (std::find(group->cargo_input, group->cargo_input + i, cargo) != group->cargo_input + i) {
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_INDPROD_CALLBACK);
- error->data = stredup("duplicate input cargo");
+ error->data = "duplicate input cargo";
return;
}
group->cargo_input[i] = cargo;
@@ -5270,7 +5270,7 @@ static void NewSpriteGroup(ByteReader *buf)
group->num_output = buf->ReadByte();
if (group->num_output > lengthof(group->add_output)) {
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_INDPROD_CALLBACK);
- error->data = stredup("too many outputs (max 16)");
+ error->data = "too many outputs (max 16)";
return;
}
for (uint i = 0; i < group->num_output; i++) {
@@ -5281,7 +5281,7 @@ static void NewSpriteGroup(ByteReader *buf)
group->version = 0xFF;
} else if (std::find(group->cargo_output, group->cargo_output + i, cargo) != group->cargo_output + i) {
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_INDPROD_CALLBACK);
- error->data = stredup("duplicate output cargo");
+ error->data = "duplicate output cargo";
return;
}
group->cargo_output[i] = cargo;
@@ -6517,7 +6517,7 @@ static void CfgApply(ByteReader *buf)
static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig *c)
{
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC, c);
- error->data = stredup(_cur.grfconfig->GetName());
+ error->data = _cur.grfconfig->GetName();
}
/* Action 0x07
@@ -6895,10 +6895,10 @@ static void GRFLoadError(ByteReader *buf)
if (buf->HasData()) {
const char *message = buf->ReadString();
- error->custom_message = stredup(TranslateTTDPatchCodes(_cur.grffile->grfid, lang, true, message, SCC_RAW_STRING_POINTER).c_str());
+ error->custom_message = TranslateTTDPatchCodes(_cur.grffile->grfid, lang, true, message, SCC_RAW_STRING_POINTER);
} else {
grfmsg(7, "GRFLoadError: No custom message supplied.");
- error->custom_message = stredup("");
+ error->custom_message.clear();
}
} else {
error->message = msgstr[message_id];
@@ -6907,10 +6907,10 @@ static void GRFLoadError(ByteReader *buf)
if (buf->HasData()) {
const char *data = buf->ReadString();
- error->data = stredup(TranslateTTDPatchCodes(_cur.grffile->grfid, lang, true, data).c_str());
+ error->data = TranslateTTDPatchCodes(_cur.grffile->grfid, lang, true, data);
} else {
grfmsg(7, "GRFLoadError: No message data supplied.");
- error->data = stredup("");
+ error->data.clear();
}
/* Only two parameter numbers can be used in the string. */
@@ -7771,7 +7771,7 @@ static void TranslateGRFStrings(ByteReader *buf)
char tmp[256];
GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE, lastof(tmp));
- error->data = stredup(tmp);
+ error->data = tmp;
return;
}
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 8452d0829..75c1977f2 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -179,7 +179,8 @@ uint _missing_extra_graphics = 0;
*/
GRFError::GRFError(StringID severity, StringID message) :
message(message),
- severity(severity)
+ severity(severity),
+ param_value()
{
}
@@ -188,23 +189,14 @@ GRFError::GRFError(StringID severity, StringID message) :
* @param error The GRFError object to make a copy of.
*/
GRFError::GRFError(const GRFError &error) :
- ZeroedMemoryAllocator(),
custom_message(error.custom_message),
data(error.data),
message(error.message),
severity(error.severity)
{
- if (error.custom_message != nullptr) this->custom_message = stredup(error.custom_message);
- if (error.data != nullptr) this->data = stredup(error.data);
memcpy(this->param_value, error.param_value, sizeof(this->param_value));
}
-GRFError::~GRFError()
-{
- free(this->custom_message);
- free(this->data);
-}
-
/**
* Create a new empty GRFParameterInfo object.
* @param nr The newgrf parameter that is changed.
diff --git a/src/newgrf_config.h b/src/newgrf_config.h
index 2c8a8559d..ef7128905 100644
--- a/src/newgrf_config.h
+++ b/src/newgrf_config.h
@@ -109,16 +109,15 @@ struct GRFIdentifier {
};
/** Information about why GRF had problems during initialisation */
-struct GRFError : ZeroedMemoryAllocator {
+struct GRFError {
GRFError(StringID severity, StringID message = 0);
GRFError(const GRFError &error);
- ~GRFError();
- char *custom_message; ///< Custom message (if present)
- char *data; ///< Additional data for message and custom_message
- StringID message; ///< Default message
- StringID severity; ///< Info / Warning / Error / Fatal
- uint32 param_value[2]; ///< Values of GRF parameters to show for message and custom_message
+ std::string custom_message; ///< Custom message (if present)
+ std::string data; ///< Additional data for message and custom_message
+ StringID message; ///< Default message
+ StringID severity; ///< Info / Warning / Error / Fatal
+ uint32 param_value[2]; ///< Values of GRF parameters to show for message and custom_message
};
/** The possible types of a newgrf parameter. */
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index 3b462f427..3f0a2ee7e 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -50,10 +50,10 @@ void ShowNewGRFError()
/* We only want to show fatal errors */
if (c->error == nullptr || c->error->severity != STR_NEWGRF_ERROR_MSG_FATAL) continue;
- SetDParam (0, c->error->custom_message == nullptr ? c->error->message : STR_JUST_RAW_STRING);
- SetDParamStr(1, c->error->custom_message);
+ SetDParam (0, c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING);
+ SetDParamStr(1, c->error->custom_message.c_str());
SetDParamStr(2, c->filename);
- SetDParamStr(3, c->error->data);
+ SetDParamStr(3, c->error->data.c_str());
for (uint i = 0; i < lengthof(c->error->param_value); i++) {
SetDParam(4 + i, c->error->param_value[i]);
}
@@ -66,13 +66,13 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint
{
if (c->error != nullptr) {
char message[512];
- SetDParamStr(0, c->error->custom_message); // is skipped by built-in messages
+ SetDParamStr(0, c->error->custom_message.c_str()); // is skipped by built-in messages
SetDParamStr(1, c->filename);
- SetDParamStr(2, c->error->data);
+ SetDParamStr(2, c->error->data.c_str());
for (uint i = 0; i < lengthof(c->error->param_value); i++) {
SetDParam(3 + i, c->error->param_value[i]);
}
- GetString(message, c->error->custom_message == nullptr ? c->error->message : STR_JUST_RAW_STRING, lastof(message));
+ GetString(message, c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING, lastof(message));
SetDParamStr(0, message);
y = DrawStringMultiLine(x, right, y, bottom, c->error->severity);