diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index f0e6d7a482..8f93043dd7 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -714,18 +714,14 @@ GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask) /** Build a string containing space separated parameter values, and terminate */ -char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last) +std::string GRFBuildParamList(const GRFConfig *c) { - uint i; - - /* Return an empty string if there are no parameters */ - if (c->num_params == 0) return strecpy(dst, "", last); - - for (i = 0; i < c->num_params; i++) { - if (i > 0) dst = strecpy(dst, " ", last); - dst += seprintf(dst, last, "%d", c->param[i]); + std::string result; + for (uint i = 0; i < c->num_params; i++) { + if (!result.empty()) result += ' '; + result += std::to_string(c->param[i]); } - return dst; + return result; } /** diff --git a/src/newgrf_config.h b/src/newgrf_config.h index 3273d001bf..171f49a604 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -220,7 +220,7 @@ void ClearGRFConfigList(GRFConfig **config); void ResetGRFConfig(bool defaults); GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig); bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR); -char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last); +std::string GRFBuildParamList(const GRFConfig *c); /* In newgrf_gui.cpp */ void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config); diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index e73dbd90e6..109a958016 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -112,10 +112,9 @@ static void ShowNewGRFInfo(const GRFConfig *c, const Rect &r, bool show_params) /* Show GRF parameter list */ if (show_params) { if (c->num_params > 0) { - char buff[256]; - GRFBuildParamList(buff, c, lastof(buff)); + std::string params = GRFBuildParamList(c); SetDParam(0, STR_JUST_RAW_STRING); - SetDParamStr(1, buff); + SetDParamStr(1, params); } else { SetDParam(0, STR_NEWGRF_SETTINGS_PARAMETER_NONE); } diff --git a/src/settings.cpp b/src/settings.cpp index e7de14a991..7ad980d172 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1134,12 +1134,9 @@ static void GRFSaveConfig(IniFile &ini, const char *grpname, const GRFConfig *li const GRFConfig *c; for (c = list; c != nullptr; c = c->next) { - char params[512]; - GRFBuildParamList(params, c, lastof(params)); - std::string key = fmt::format("{:08X}|{}|{}", BSWAP32(c->ident.grfid), FormatArrayAsHex(c->ident.md5sum), c->filename); - group->GetItem(key, true)->SetValue(params); + group->GetItem(key, true)->SetValue(GRFBuildParamList(c)); } }