From 2f8c51a5529686959c6f6c5a8e899127b16c345d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 10 Jul 2013 14:15:12 -0300 Subject: [PATCH] use unsigneds for unary minus, too --- lbaselib.c | 4 ++-- lobject.c | 7 +++---- lvm.c | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lbaselib.c b/lbaselib.c index 30e19ee4..f3964c70 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.278 2013/07/05 14:35:49 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.279 2013/07/05 14:39:15 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -63,7 +63,7 @@ static int b_str2int (const char *s, const char *e, int base, lua_Integer *pn) { s += strspn(s, SPACECHARS); /* skip trailing spaces */ if (s != e) /* invalid trailing characters? */ return 0; - *pn = (neg) ? -(lua_Integer)n : (lua_Integer)n; + *pn = (lua_Integer)((neg) ? (0u - n) : n); return 1; } diff --git a/lobject.c b/lobject.c index dcd81a96..92721332 100644 --- a/lobject.c +++ b/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 2.66 2013/06/04 19:36:42 roberto Exp roberto $ +** $Id: lobject.c,v 2.67 2013/06/25 18:58:32 roberto Exp roberto $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ @@ -78,7 +78,7 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1, case LUA_OPMUL:return intop(*, v1, v2); case LUA_OPMOD: return luaV_mod(L, v1, v2); case LUA_OPPOW: return luaV_pow(v1, v2); - case LUA_OPUNM: return -v1; + case LUA_OPUNM: return intop(-, 0, v1); default: lua_assert(0); return 0; } } @@ -260,8 +260,7 @@ int luaO_str2int (const char *s, size_t len, lua_Integer *result) { while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */ if (empty || s != ends) return 0; /* something wrong in the numeral */ else { - if (neg) *result = -cast(lua_Integer, a); - else *result = cast(lua_Integer, a); + *result = cast_integer((neg) ? 0u - a : a); return 1; } } diff --git a/lvm.c b/lvm.c index fc335876..67aa58f8 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.174 2013/06/19 14:27:00 roberto Exp roberto $ +** $Id: lvm.c,v 2.175 2013/06/20 15:02:49 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -334,7 +334,7 @@ lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y) { if (y == 0) luaG_runerror(L, "attempt to divide by zero"); else /* -1 */ - return -x; /* avoid overflow with 0x80000... */ + return intop(-, 0, x); /* avoid overflow with 0x80000... */ } else { lua_Integer d = x / y; /* perform division */ @@ -699,7 +699,7 @@ void luaV_execute (lua_State *L) { lua_Number nb; if (ttisinteger(rb)) { lua_Integer ib = ivalue(rb); - setivalue(ra, -ib); + setivalue(ra, intop(-, 0, ib)); } else if (tonumber(rb, &nb)) { setnvalue(ra, luai_numunm(L, nb));