mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r26777) -Codechange: use safe string functions in squirrel code as well, and prevent using the ones that are deemed unsafe
This commit is contained in:
parent
962c1a3242
commit
eb52e65bec
|
@ -1,9 +1,14 @@
|
|||
/* see copyright notice in squirrel.h */
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include <sqstdaux.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
void sqstd_printcallstack(HSQUIRRELVM v)
|
||||
{
|
||||
SQPRINTFUNCTION pf = sq_getprintfunc(v);
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
/* see copyright notice in squirrel.h */
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <sqstdmath.h>
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
#define SINGLE_ARG_FUNC(_funcname, num_ops) static SQInteger math_##_funcname(HSQUIRRELVM v){ \
|
||||
SQFloat f; \
|
||||
sq_decreaseops(v,num_ops); \
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
|
@ -14,6 +17,10 @@
|
|||
#include "sqfuncstate.h"
|
||||
#include "sqclass.h"
|
||||
|
||||
#include "../../../string_func.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
bool sq_aux_gettypedarg(HSQUIRRELVM v,SQInteger idx,SQObjectType type,SQObjectPtr **o)
|
||||
{
|
||||
*o = &stack_get(v,idx);
|
||||
|
@ -40,8 +47,9 @@ SQInteger sq_aux_throwobject(HSQUIRRELVM v,SQObjectPtr &e)
|
|||
|
||||
SQInteger sq_aux_invalidtype(HSQUIRRELVM v,SQObjectType type)
|
||||
{
|
||||
sprintf(_ss(v)->GetScratchPad(100), "unexpected type %s", IdType2Name(type));
|
||||
return sq_throwerror(v, _ss(v)->GetScratchPad(-1));
|
||||
char buf[100];
|
||||
seprintf(buf, lastof(buf), "unexpected type %s", IdType2Name(type));
|
||||
return sq_throwerror(v, buf);
|
||||
}
|
||||
|
||||
HSQUIRRELVM sq_open(SQInteger initialstacksize)
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
*/
|
||||
/* Needs to be first due to a squirrel header defining type() and type()
|
||||
* being used in some versions of the headers included by algorithm. */
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
|
@ -16,6 +19,8 @@
|
|||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
bool str2num(const SQChar *s,SQObjectPtr &res)
|
||||
{
|
||||
SQChar *end;
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
#include "sqtable.h"
|
||||
#include "sqclass.h"
|
||||
#include "sqclosure.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
SQClass::SQClass(SQSharedState *ss,SQClass *base)
|
||||
{
|
||||
_base = base;
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "sqpcheader.h"
|
||||
#include <stdarg.h>
|
||||
|
@ -13,6 +16,10 @@
|
|||
#include "sqvm.h"
|
||||
#include "sqtable.h"
|
||||
|
||||
#include "../../../string_func.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
#define DEREF_NO_DEREF -1
|
||||
#define DEREF_FIELD -2
|
||||
|
||||
|
@ -66,7 +73,7 @@ public:
|
|||
static SQChar temp[256];
|
||||
va_list vl;
|
||||
va_start(vl, s);
|
||||
vsnprintf(temp, sizeof(temp), s, vl);
|
||||
vseprintf(temp, lastof(temp), s, vl);
|
||||
va_end(vl);
|
||||
throw temp;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "sqpcheader.h"
|
||||
#include <stdarg.h>
|
||||
|
@ -9,6 +12,11 @@
|
|||
#include "sqclosure.h"
|
||||
#include "sqstring.h"
|
||||
|
||||
#include "../../../core/alloc_func.hpp"
|
||||
#include "../../../string_func.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi)
|
||||
{
|
||||
SQInteger cssize = v->_callsstacksize;
|
||||
|
@ -60,9 +68,12 @@ void SQVM::Raise_Error(const SQChar *s, ...)
|
|||
{
|
||||
va_list vl;
|
||||
va_start(vl, s);
|
||||
vsprintf(_sp(rsl((SQInteger)strlen(s)+(NUMBER_MAX_CHAR*2))), s, vl);
|
||||
size_t len = strlen(s)+(NUMBER_MAX_CHAR*2);
|
||||
char *buffer = MallocT<char>(len + 1);
|
||||
vseprintf(buffer, buffer + len, s, vl);
|
||||
va_end(vl);
|
||||
_lasterror = SQString::Create(_ss(this),_spval,-1);
|
||||
_lasterror = SQString::Create(_ss(this),buffer,-1);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void SQVM::Raise_Error(SQObjectPtr &desc)
|
||||
|
@ -72,16 +83,15 @@ void SQVM::Raise_Error(SQObjectPtr &desc)
|
|||
|
||||
SQString *SQVM::PrintObjVal(const SQObject &o)
|
||||
{
|
||||
char buf[NUMBER_MAX_CHAR+1];
|
||||
switch(type(o)) {
|
||||
case OT_STRING: return _string(o);
|
||||
case OT_INTEGER:
|
||||
sprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), SQ_PRINTF64, _integer(o));
|
||||
return SQString::Create(_ss(this), _spval);
|
||||
break;
|
||||
seprintf(buf, lastof(buf), SQ_PRINTF64, _integer(o));
|
||||
return SQString::Create(_ss(this), buf);
|
||||
case OT_FLOAT:
|
||||
sprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), "%.14g", _float(o));
|
||||
return SQString::Create(_ss(this), _spval);
|
||||
break;
|
||||
seprintf(buf, lastof(buf), "%.14g", _float(o));
|
||||
return SQString::Create(_ss(this), buf);
|
||||
default:
|
||||
return SQString::Create(_ss(this), GetTypeName(o));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqcompiler.h"
|
||||
#include "sqfuncproto.h"
|
||||
|
@ -9,6 +12,8 @@
|
|||
#include "sqopcodes.h"
|
||||
#include "sqfuncstate.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
#ifdef _DEBUG_DUMP
|
||||
SQInstructionDesc g_InstrDesc[]={
|
||||
{"_OP_LINE"},
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -9,9 +12,10 @@
|
|||
#include "sqcompiler.h"
|
||||
#include "sqlexer.h"
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
#include "../../../string_func.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
#define CUR_CHAR (_currdata)
|
||||
#define RETURN_TOKEN(t) { _prevtoken = _curtoken; _curtoken = t; return t;}
|
||||
#define IS_EOB() (CUR_CHAR <= SQUIRREL_EOB)
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
#include "sqpcheader.h"
|
||||
void *sq_vm_malloc(SQUnsignedInteger size){ return malloc((size_t)size); }
|
||||
|
||||
void *sq_vm_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size){ return realloc(p, (size_t)size); }
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
|
||||
#include "../../../core/alloc_func.hpp"
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
void *sq_vm_malloc(SQUnsignedInteger size){ return MallocT<char>((size_t)size); }
|
||||
|
||||
void *sq_vm_realloc(void *p, SQUnsignedInteger oldsize, SQUnsignedInteger size){ return ReallocT<char>(static_cast<char*>(p), (size_t)size); }
|
||||
|
||||
void sq_vm_free(void *p, SQUnsignedInteger size){ free(p); }
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
#include "sqstring.h"
|
||||
|
@ -11,6 +14,8 @@
|
|||
#include "sqclass.h"
|
||||
#include "sqclosure.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
|
||||
const SQChar *IdType2Name(SQObjectType type)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqopcodes.h"
|
||||
#include "sqvm.h"
|
||||
|
@ -12,6 +15,8 @@
|
|||
#include "squserdata.h"
|
||||
#include "sqclass.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
SQObjectPtr _null_;
|
||||
SQObjectPtr _true_(true);
|
||||
SQObjectPtr _false_(false);
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include "sqpcheader.h"
|
||||
#include "sqvm.h"
|
||||
#include "sqtable.h"
|
||||
#include "sqfuncproto.h"
|
||||
#include "sqclosure.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
SQTable::SQTable(SQSharedState *ss,SQInteger nInitialSize)
|
||||
{
|
||||
SQInteger pow2size=MINPOWER2;
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
see copyright notice in squirrel.h
|
||||
*/
|
||||
|
||||
#include "../../../stdafx.h"
|
||||
|
||||
#include <squirrel.h>
|
||||
#include "sqpcheader.h"
|
||||
#include <math.h>
|
||||
|
@ -15,6 +18,10 @@
|
|||
#include "sqarray.h"
|
||||
#include "sqclass.h"
|
||||
|
||||
#include "../../../string_func.h"
|
||||
|
||||
#include "../../../safeguards.h"
|
||||
|
||||
#define TOP() (_stack._vals[_top-1])
|
||||
|
||||
#define CLEARSTACK(_last_top) { if((_last_top) >= _top) ClearStack(_last_top); }
|
||||
|
@ -251,18 +258,19 @@ bool SQVM::CMP_OP(CmpOP op, const SQObjectPtr &o1,const SQObjectPtr &o2,SQObject
|
|||
|
||||
void SQVM::ToString(const SQObjectPtr &o,SQObjectPtr &res)
|
||||
{
|
||||
char buf[64];
|
||||
switch(type(o)) {
|
||||
case OT_STRING:
|
||||
res = o;
|
||||
return;
|
||||
case OT_FLOAT:
|
||||
sprintf(_sp(rsl(NUMBER_MAX_CHAR+1)),"%g",_float(o));
|
||||
seprintf(buf, lastof(buf),"%g",_float(o));
|
||||
break;
|
||||
case OT_INTEGER:
|
||||
sprintf(_sp(rsl(NUMBER_MAX_CHAR+1)),SQ_PRINTF64,_integer(o));
|
||||
seprintf(buf, lastof(buf),SQ_PRINTF64,_integer(o));
|
||||
break;
|
||||
case OT_BOOL:
|
||||
sprintf(_sp(rsl(6)),_integer(o)?"true":"false");
|
||||
seprintf(buf, lastof(buf),_integer(o)?"true":"false");
|
||||
break;
|
||||
case OT_TABLE:
|
||||
case OT_USERDATA:
|
||||
|
@ -276,9 +284,9 @@ void SQVM::ToString(const SQObjectPtr &o,SQObjectPtr &res)
|
|||
}
|
||||
}
|
||||
default:
|
||||
sprintf(_sp(rsl(sizeof(void*)+20)),"(%s : 0x%p)",GetTypeName(o),(void*)_rawval(o));
|
||||
seprintf(buf, lastof(buf),"(%s : 0x%p)",GetTypeName(o),(void*)_rawval(o));
|
||||
}
|
||||
res = SQString::Create(_ss(this),_spval);
|
||||
res = SQString::Create(_ss(this),buf);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue