summaryrefslogtreecommitdiff
path: root/src/script/squirrel_std.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-09-06 19:28:09 +0000
committerrubidium <rubidium@openttd.org>2014-09-06 19:28:09 +0000
commit962c1a3242e213a65078ed4217112978ddb0c613 (patch)
tree6e4f30157cab540e39ba24a04d0a6f3c29156691 /src/script/squirrel_std.cpp
parente63ca12ab815e0cd4d5cc7fd129cde04f7c4404a (diff)
downloadopenttd-962c1a3242e213a65078ed4217112978ddb0c613.tar.xz
(svn r26776) -Codechange: use safe string functions in script/squirrel*.cpp
Diffstat (limited to 'src/script/squirrel_std.cpp')
-rw-r--r--src/script/squirrel_std.cpp25
1 files changed, 7 insertions, 18 deletions
diff --git a/src/script/squirrel_std.cpp b/src/script/squirrel_std.cpp
index ccebe2015..78cce518d 100644
--- a/src/script/squirrel_std.cpp
+++ b/src/script/squirrel_std.cpp
@@ -18,12 +18,7 @@
#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.
- * TODO: use properly safe functions now that Squirrel uses chars exclusively. */
#include "../safeguards.h"
-#undef strcat
-#undef strdup
SQInteger SquirrelStd::min(HSQUIRRELVM vm)
@@ -50,7 +45,6 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm)
{
SQInteger top = sq_gettop(vm);
const SQChar *filename;
- SQChar *real_filename;
sq_getstring(vm, 2, &filename);
@@ -61,31 +55,26 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm)
DEBUG(misc, 0, "[squirrel] Couldn't detect the script-name of the 'require'-caller; this should never happen!");
return SQ_ERROR;
}
- real_filename = strdup(si.source);
+
+ char path[MAX_PATH];
+ strecpy(path, si.source, lastof(path));
/* Keep the dir, remove the rest */
- SQChar *s = strrchr(real_filename, PATHSEPCHAR);
+ SQChar *s = strrchr(path, PATHSEPCHAR);
if (s != NULL) {
/* Keep the PATHSEPCHAR there, remove the rest */
s++;
*s = '\0';
}
- /* And now we concat, so we are relative from the current script
- * First, we have to make sure we have enough space for the full path */
- real_filename = ReallocT(real_filename, strlen(real_filename) + strlen(filename) + 1);
- strcat(real_filename, filename);
- /* Tars dislike opening files with '/' on Windows.. so convert it to '\\' ;) */
- char *filen = stredup(real_filename);
+ strecat(path, filename, lastof(path));
#if (PATHSEPCHAR != '/')
- for (char *n = filen; *n != '\0'; n++) if (*n == '/') *n = PATHSEPCHAR;
+ for (char *n = path; *n != '\0'; n++) if (*n == '/') *n = PATHSEPCHAR;
#endif
Squirrel *engine = (Squirrel *)sq_getforeignptr(vm);
- bool ret = engine->LoadScript(vm, filen);
+ bool ret = engine->LoadScript(vm, path);
/* Reset the top, so the stack stays correct */
sq_settop(vm, top);
- free(real_filename);
- free(filen);
return ret ? 0 : SQ_ERROR;
}