Browse Source

Fix improper handling of negative values introduced by transfering code from squirrel

mingodad 10 years ago
parent
commit
1b445be88f

+ 2 - 2
SquiLu/include/squirrel.h

@@ -156,7 +156,7 @@ typedef wchar_t USQChar;
 #else
 #define scstrtol	wcstol
 #endif
-#define scatoi		_wtoi
+//#define scatoi		_wtoi
 #define scstrtoul	wcstoul
 #define scstrstr	wcsstr
 #define scstrpbrk	wcspbrk
@@ -189,7 +189,7 @@ typedef unsigned char USQChar;
 #else
 #define scstrtol	strtol
 #endif
-#define scatoi		atoi
+//#define scatoi		atoi
 #define scstrtoul	strtoul
 #define scvfprintf	vfprintf
 #define scvsprintf	vsprintf

+ 0 - 1
SquiLu/sqstdlib/sqstdstring.cpp

@@ -62,7 +62,6 @@ static SQRESULT validate_format(HSQUIRRELVM v, SQChar *fmt, const SQChar *src, S
 		swidth[wc] = _SC('\0');
 		if(wc > 0) {
 			width += scstrtol(swidth,&dummy,10);
-
 		}
 	}
 	if (n-start > MAX_FORMAT_LEN )

+ 9 - 2
SquiLu/squirrel/sqapi.cpp

@@ -1392,6 +1392,12 @@ const SQChar *sq_getlasterror_str(HSQUIRRELVM v)
 	return _stringval(v->_lasterror);
 }
 
+void sq_getlasterror_line_col(HSQUIRRELVM v, SQInteger *line, SQInteger *column)
+{
+    *line = v->_lasterror_line;
+    *column = v->_lasterror_column;
+}
+
 SQRESULT sq_reservestack(HSQUIRRELVM v,SQInteger nsize)
 {
 	if (((SQUnsignedInteger)v->_top + nsize) > v->_stack.size()) {
@@ -1405,10 +1411,11 @@ SQRESULT sq_reservestack(HSQUIRRELVM v,SQInteger nsize)
 
 SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror)
 {
-	if (type(v->GetUp(-1)) == OT_GENERATOR)
+    SQObjectPtr &obj = v->GetUp(-1);
+	if(type(obj)==OT_GENERATOR)
 	{
 		v->PushNull(); //retval
-		if (!v->Execute(v->GetUp(-2), 0, v->_top, v->GetUp(-1), raiseerror, SQVM::ET_RESUME_GENERATOR))
+		if (!v->Execute(v->GetUp(-2), 0, v->_top, obj, raiseerror, SQVM::ET_RESUME_GENERATOR))
 		{v->Raise_Error(v->_lasterror); return SQ_ERROR;}
 		if(!retval)
 			v->Pop();

+ 1 - 1
SquiLu/squirrel/sqbaselib.cpp

@@ -35,7 +35,7 @@ bool str2num(const SQChar *s,SQObjectPtr &res, SQInteger base=10)
 		res = r;
 	}
 	else{
-		SQInteger r = SQInteger(scstrtol(s,&end, base));
+		SQInteger r = SQInteger(scstrtol(s,&end,(int)base));
 		if(s == end) return false;
 		res = r;
 	}

+ 3 - 1
SquiLu/squirrel/sqcompiler.cpp

@@ -1097,7 +1097,9 @@ public:
 		if(target < 0) {
 			target = _fs->PushTarget();
 		}
-		if(value <= INT_MAX && value > INT_MIN) { //does it fit in 32 bits?
+		//with the line bellow we get wrong result for -1
+		//if(value <= INT_MAX && value > INT_MIN) { //does it fit in 32 bits?
+		if((value & (~((SQInteger)0xFFFFFFFF))) == 0) { //does it fit in 32 bits?
 			_fs->AddInstruction(_OP_LOADINT, target,value);
 		}
 		else {

+ 2 - 1
SquiLu/squirrel/sqlexer.cpp

@@ -622,7 +622,8 @@ SQInteger SQLexer::ReadNumber()
 	case TINT:
 	case THEX:
 	case TOCTAL:
-        if(itmp > INT_MAX) Error(_SC("integer overflow"));
+	    //to allow 64 bits integers comment bellow
+        //if(itmp > INT_MAX) Error(_SC("integer overflow %ulld %d"));
         _nvalue = (SQInteger) itmp;
 		return TK_INTEGER;
 	}