summaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/lvm.c b/lvm.c
index f30806bd..4efc2949 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.195 2014/04/09 17:05:11 roberto Exp roberto $ 2** $Id: lvm.c,v 2.196 2014/04/11 19:02:16 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -88,7 +88,7 @@ int luaV_tostring (lua_State *L, StkId obj) {
88*/ 88*/
89int luaV_numtointeger (lua_Number n, lua_Integer *p) { 89int luaV_numtointeger (lua_Number n, lua_Integer *p) {
90 if (cast_num(LUA_MININTEGER) <= n && n < (LUA_MAXINTEGER + cast_num(1))) { 90 if (cast_num(LUA_MININTEGER) <= n && n < (LUA_MAXINTEGER + cast_num(1))) {
91 *p = cast_integer(n); 91 *p = cast(lua_Integer, n);
92 lua_assert(cast_num(*p) == n); 92 lua_assert(cast_num(*p) == n);
93 return 1; 93 return 1;
94 } 94 }
@@ -343,7 +343,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
343 343
344 344
345lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y) { 345lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y) {
346 if (cast_unsigned(y) + 1u <= 1u) { /* special cases: -1 or 0 */ 346 if (cast_s2u(y) + 1u <= 1u) { /* special cases: -1 or 0 */
347 if (y == 0) 347 if (y == 0)
348 luaG_runerror(L, "attempt to divide by zero"); 348 luaG_runerror(L, "attempt to divide by zero");
349 return intop(-, 0, x); /* y==-1; avoid overflow with 0x80000...//-1 */ 349 return intop(-, 0, x); /* y==-1; avoid overflow with 0x80000...//-1 */
@@ -359,7 +359,7 @@ lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y) {
359 359
360 360
361lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y) { 361lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y) {
362 if (cast_unsigned(y) + 1u <= 1u) { /* special cases: -1 or 0 */ 362 if (cast_s2u(y) + 1u <= 1u) { /* special cases: -1 or 0 */
363 if (y == 0) 363 if (y == 0)
364 luaG_runerror(L, "attempt to perform 'n%%0'"); 364 luaG_runerror(L, "attempt to perform 'n%%0'");
365 return 0; /* y==-1; avoid overflow with 0x80000...%-1 */ 365 return 0; /* y==-1; avoid overflow with 0x80000...%-1 */
@@ -398,11 +398,11 @@ lua_Integer luaV_pow (lua_State *L, lua_Integer x, lua_Integer y) {
398lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) { 398lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {
399 if (y < 0) { /* shift right? */ 399 if (y < 0) { /* shift right? */
400 if (y <= -NBITS) return 0; 400 if (y <= -NBITS) return 0;
401 else return cast_integer(cast_unsigned(x) >> (-y)); 401 else return intop(>>, x, -y);
402 } 402 }
403 else { /* shift left */ 403 else { /* shift left */
404 if (y >= NBITS) return 0; 404 if (y >= NBITS) return 0;
405 else return x << y; 405 else return intop(<<, x, y);
406 } 406 }
407} 407}
408 408
@@ -792,7 +792,7 @@ void luaV_execute (lua_State *L) {
792 TValue *rb = RB(i); 792 TValue *rb = RB(i);
793 lua_Integer ib; 793 lua_Integer ib;
794 if (tointeger(rb, &ib)) { 794 if (tointeger(rb, &ib)) {
795 setivalue(ra, intop(^, cast_integer(-1), ib)); 795 setivalue(ra, intop(^, ~cast_s2u(0), ib));
796 } 796 }
797 else { 797 else {
798 Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT)); 798 Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));