summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-04-24 04:41:54 +0000
committerrubidium <rubidium@openttd.org>2014-04-24 04:41:54 +0000
commitb4914b91d9dc5fb007fd0705ef1678fe9f71848c (patch)
treef22cd9ac404f5c0e00eed492004cb5a41753328d /src/script
parentae46990636684052932d659cb23cd46bf016d824 (diff)
downloadopenttd-b4914b91d9dc5fb007fd0705ef1678fe9f71848c.tar.xz
(svn r26493) -Codechange: use strecat to concatenate script settings instead of manually accounting for the amount of characters that has been written
Diffstat (limited to 'src/script')
-rw-r--r--src/script/script_config.cpp22
-rw-r--r--src/script/script_config.hpp2
2 files changed, 12 insertions, 12 deletions
diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp
index 48a1459d9..95e278954 100644
--- a/src/script/script_config.cpp
+++ b/src/script/script_config.cpp
@@ -184,27 +184,27 @@ void ScriptConfig::StringToSettings(const char *value)
free(value_copy);
}
-void ScriptConfig::SettingsToString(char *string, size_t size) const
+void ScriptConfig::SettingsToString(char *string, const char *last) const
{
- string[0] = '\0';
+ char *s = string;
+ *s = '\0';
for (SettingValueList::const_iterator it = this->settings.begin(); it != this->settings.end(); it++) {
char no[10];
seprintf(no, lastof(no), "%d", (*it).second);
/* Check if the string would fit in the destination */
- size_t needed_size = strlen((*it).first) + 1 + strlen(no) + 1;
+ size_t needed_size = strlen((*it).first) + 1 + strlen(no);
/* If it doesn't fit, skip the next settings */
- if (size <= needed_size) break;
- size -= needed_size;
+ if (string + needed_size > last) break;
- strcat(string, (*it).first);
- strcat(string, "=");
- strcat(string, no);
- strcat(string, ",");
+ s = strecat(s, last, (*it).first);
+ s = strecat(s, last, "=");
+ s = strecat(s, last, no);
+ s = strecat(s, last, ",");
}
+
/* Remove the last ',', but only if at least one setting was saved. */
- size_t len = strlen(string);
- if (len > 0) string[len - 1] = '\0';
+ if (s != string) s[-1] = '\0';
}
const char *ScriptConfig::GetTextfile(TextfileType type, CompanyID slot) const
diff --git a/src/script/script_config.hpp b/src/script/script_config.hpp
index 0350f8ded..dfc675473 100644
--- a/src/script/script_config.hpp
+++ b/src/script/script_config.hpp
@@ -172,7 +172,7 @@ public:
* Convert the custom settings to a string that can be stored in the config
* file or savegames.
*/
- void SettingsToString(char *string, size_t size) const;
+ void SettingsToString(char *string, const char *last) const;
/**
* Search a textfile file next to this script.