aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-04-27 11:42:26 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-04-27 11:42:26 -0300
commit68616c6669f6029d96cb9c683f81d652274d4df2 (patch)
treedcf47612ad5667bd2338e34ccda3ffa44f44a7a3
parente98ba351cebaec72f56acceddd82338cc37c3265 (diff)
downloadlua-68616c6669f6029d96cb9c683f81d652274d4df2.tar.gz
lua-68616c6669f6029d96cb9c683f81d652274d4df2.tar.bz2
lua-68616c6669f6029d96cb9c683f81d652274d4df2.zip
using lua_Unsigned (instead of lua_Integer) for bit manipulation
-rw-r--r--lstrlib.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 2b21a132..bbf6fbb1 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.196 2014/04/14 16:59:46 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.197 2014/04/16 18:48:31 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1013,8 +1013,8 @@ static int dumpint (char *buff, lua_Integer m, int littleendian, int size) {
1013 if (size < SZINT) { /* need test for overflow? */ 1013 if (size < SZINT) { /* need test for overflow? */
1014 /* OK if there are only zeros left in higher bytes, 1014 /* OK if there are only zeros left in higher bytes,
1015 or only ones left (excluding non-signal bits in last byte) */ 1015 or only ones left (excluding non-signal bits in last byte) */
1016 return ((n & ~(lua_Integer)MC) == 0 || 1016 return ((n & ~(lua_Unsigned)MC) == 0 ||
1017 (n | SM) == ~(lua_Integer)0); 1017 (n | SM) == ~(lua_Unsigned)0);
1018 } 1018 }
1019 else return 1; /* no overflow can occur with full size */ 1019 else return 1; /* no overflow can occur with full size */
1020} 1020}
@@ -1039,7 +1039,7 @@ static int dumpint_l (lua_State *L) {
1039 1039
1040static int undumpint (const char *buff, lua_Integer *res, 1040static int undumpint (const char *buff, lua_Integer *res,
1041 int littleendian, int size) { 1041 int littleendian, int size) {
1042 lua_Integer n = 0; 1042 lua_Unsigned n = 0;
1043 int i; 1043 int i;
1044 for (i = 0; i < size; i++) { 1044 for (i = 0; i < size; i++) {
1045 if (i >= SZINT) { /* will throw away a byte? */ 1045 if (i >= SZINT) { /* will throw away a byte? */
@@ -1053,13 +1053,14 @@ static int undumpint (const char *buff, lua_Integer *res,
1053 return 0; /* overflow */ 1053 return 0; /* overflow */
1054 } 1054 }
1055 n <<= NB; 1055 n <<= NB;
1056 n |= (lua_Integer)(unsigned char)buff[littleendian ? size - 1 - i : i]; 1056 n |= (lua_Unsigned)(unsigned char)buff[littleendian ? size - 1 - i : i];
1057 } 1057 }
1058 if (size < SZINT) { /* need sign extension? */ 1058 if (size < SZINT) { /* need sign extension? */
1059 lua_Unsigned mask = (lua_Unsigned)1 << (size*NB - 1); 1059 lua_Unsigned mask = (lua_Unsigned)1 << (size*NB - 1);
1060 n = (lua_Integer)((n ^ mask) - mask); /* do sign extension */ 1060 *res = (lua_Integer)((n ^ mask) - mask); /* do sign extension */
1061 } 1061 }
1062 *res = n; 1062 else
1063 *res = (lua_Integer)n;
1063 return 1; 1064 return 1;
1064} 1065}
1065 1066