From 6d6e2232ead8bd13b7e302f60793809f0e39ac0d Mon Sep 17 00:00:00 2001 From: glx Date: Mon, 2 Feb 2009 13:46:26 +0000 Subject: (svn r15316) -Fix [NoAI]: ignore unprintable chars when returning a string to squirrel --- src/script/squirrel_helper.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/script') diff --git a/src/script/squirrel_helper.hpp b/src/script/squirrel_helper.hpp index 67baf7c51..73daeb5d5 100644 --- a/src/script/squirrel_helper.hpp +++ b/src/script/squirrel_helper.hpp @@ -9,6 +9,7 @@ #include "../core/math_func.hpp" #include "../core/smallvec_type.hpp" #include "../economy_type.h" +#include "../string_func.h" #include "squirrel_helper_type.hpp" /** @@ -79,8 +80,8 @@ namespace SQConvert { template <> inline int Return (HSQUIRRELVM vm, int64 res) { sq_pushinteger(vm, ClampToI32(res)); return 1; } template <> inline int Return (HSQUIRRELVM vm, Money res) { sq_pushinteger(vm, ClampToI32(res)); return 1; } template <> inline int Return (HSQUIRRELVM vm, bool res) { sq_pushbool (vm, res); return 1; } - template <> inline int Return (HSQUIRRELVM vm, char *res) { if (res == NULL) sq_pushnull(vm); else sq_pushstring (vm, OTTD2FS(res), strlen(res)); free(res); return 1; } - template <> inline int Return(HSQUIRRELVM vm, const char *res) { if (res == NULL) sq_pushnull(vm); else sq_pushstring (vm, OTTD2FS(res), strlen(res)); return 1; } + template <> inline int Return (HSQUIRRELVM vm, char *res) { if (res == NULL) sq_pushnull(vm); else {str_validate(res, false, true); sq_pushstring (vm, OTTD2FS(res), strlen(res)); free(res);} return 1; } + template <> inline int Return(HSQUIRRELVM vm, const char *res) { if (res == NULL) sq_pushnull(vm); else {str_validate((char*)res, false, true); sq_pushstring (vm, OTTD2FS(res), strlen(res));} return 1; } template <> inline int Return (HSQUIRRELVM vm, void *res) { sq_pushuserpointer(vm, res); return 1; } /** -- cgit v1.2.3-54-g00ecf