summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-04-24 17:40:43 +0000
committerrubidium <rubidium@openttd.org>2014-04-24 17:40:43 +0000
commit24fdd0b7bb543ba90f48c5cea35f2a36c16a33a5 (patch)
tree794c9ab88ee810c51b4fb8b5067dd515a66ff4a0 /src
parentb4914b91d9dc5fb007fd0705ef1678fe9f71848c (diff)
downloadopenttd-24fdd0b7bb543ba90f48c5cea35f2a36c16a33a5.tar.xz
(svn r26494) -Codechange: replace some further usages of s(n)printf with seprintf
Diffstat (limited to 'src')
-rw-r--r--src/script/squirrel.cpp10
-rw-r--r--src/script/squirrel_std.cpp3
-rw-r--r--src/settings.cpp15
3 files changed, 20 insertions, 8 deletions
diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp
index 2c50b964a..9ead866e7 100644
--- a/src/script/squirrel.cpp
+++ b/src/script/squirrel.cpp
@@ -19,7 +19,12 @@
#include <../squirrel/sqpcheader.h>
#include <../squirrel/sqvm.h>
+/* Due to the different characters for Squirrel, the scsnprintf might be a simple
+ * snprint which triggers the safeguard. But it isn't always a simple snprintf.
+ * Likewise for scstrcat. */
#include "../safeguards.h"
+#undef snprintf
+#undef strcat
void Squirrel::CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column)
{
@@ -287,8 +292,9 @@ bool Squirrel::CallBoolMethod(HSQOBJECT instance, const char *method_name, bool
sq_pushroottable(vm);
if (prepend_API_name) {
- char *class_name2 = (char *)alloca(strlen(class_name) + strlen(engine->GetAPIName()) + 1);
- sprintf(class_name2, "%s%s", engine->GetAPIName(), class_name);
+ size_t len = strlen(class_name) + strlen(engine->GetAPIName()) + 1;
+ char *class_name2 = (char *)alloca(len);
+ seprintf(class_name2, class_name2 + len - 1, "%s%s", engine->GetAPIName(), class_name);
sq_pushstring(vm, OTTD2SQ(class_name2), -1);
} else {
diff --git a/src/script/squirrel_std.cpp b/src/script/squirrel_std.cpp
index a6f19a5dd..f09471554 100644
--- a/src/script/squirrel_std.cpp
+++ b/src/script/squirrel_std.cpp
@@ -17,7 +17,10 @@
#include "../core/alloc_func.hpp"
#include "../core/math_func.hpp"
+/* 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
SQInteger SquirrelStd::min(HSQUIRRELVM vm)
diff --git a/src/settings.cpp b/src/settings.cpp
index 27c3c910b..4cb323eba 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1674,8 +1674,9 @@ void GetGRFPresetList(GRFPresetList *list)
*/
GRFConfig *LoadGRFPresetFromConfig(const char *config_name)
{
- char *section = (char*)alloca(strlen(config_name) + 8);
- sprintf(section, "preset-%s", config_name);
+ size_t len = strlen(config_name) + 8;
+ char *section = (char*)alloca(len);
+ seprintf(section, section + len - 1, "preset-%s", config_name);
IniFile *ini = IniLoadConfig();
GRFConfig *config = GRFLoadConfig(ini, section, false);
@@ -1692,8 +1693,9 @@ GRFConfig *LoadGRFPresetFromConfig(const char *config_name)
*/
void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
{
- char *section = (char*)alloca(strlen(config_name) + 8);
- sprintf(section, "preset-%s", config_name);
+ size_t len = strlen(config_name) + 8;
+ char *section = (char*)alloca(len);
+ seprintf(section, section + len - 1, "preset-%s", config_name);
IniFile *ini = IniLoadConfig();
GRFSaveConfig(ini, section, config);
@@ -1707,8 +1709,9 @@ void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
*/
void DeleteGRFPresetFromConfig(const char *config_name)
{
- char *section = (char*)alloca(strlen(config_name) + 8);
- sprintf(section, "preset-%s", config_name);
+ size_t len = strlen(config_name) + 8;
+ char *section = (char*)alloca(len);
+ seprintf(section, section + len - 1, "preset-%s", config_name);
IniFile *ini = IniLoadConfig();
ini->RemoveGroup(section);