aboutsummaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstrlib.c')
-rw-r--r--lstrlib.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 46b06568..98cd20f7 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.186 2014/02/25 14:30:21 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.187 2014/03/12 18:09:06 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*/
@@ -1005,7 +1005,7 @@ static int packint (char *buff, lua_Integer n, int littleendian, int size) {
1005 } 1005 }
1006 buff[i] = (n & MC); /* last byte */ 1006 buff[i] = (n & MC); /* last byte */
1007 /* test for overflow: OK if there are only zeros left in higher bytes, 1007 /* test for overflow: OK if there are only zeros left in higher bytes,
1008 or if there are only oneś left and packed number is negative (signal 1008 or if there are only ones left and packed number is negative (signal
1009 bit, the higher bit in last byte, is one) */ 1009 bit, the higher bit in last byte, is one) */
1010 return ((n & ~MC) == 0 || (n | SM) == ~(lua_Integer)0); 1010 return ((n & ~MC) == 0 || (n | SM) == ~(lua_Integer)0);
1011} 1011}
@@ -1027,7 +1027,7 @@ static int packint_l (lua_State *L) {
1027/* mask to check higher-order byte in a Lua integer */ 1027/* mask to check higher-order byte in a Lua integer */
1028#define HIGHERBYTE (MC << (NB * (SZINT - 1))) 1028#define HIGHERBYTE (MC << (NB * (SZINT - 1)))
1029 1029
1030/* mask to check higher-order byte + signal bit of next byte */ 1030/* mask to check higher-order byte + signal bit of next (lower) byte */
1031#define HIGHERBYTE1 (HIGHERBYTE | (HIGHERBYTE >> 1)) 1031#define HIGHERBYTE1 (HIGHERBYTE | (HIGHERBYTE >> 1))
1032 1032
1033static int unpackint (const char *buff, lua_Integer *res, 1033static int unpackint (const char *buff, lua_Integer *res,
@@ -1037,12 +1037,12 @@ static int unpackint (const char *buff, lua_Integer *res,
1037 for (i = 0; i < size; i++) { 1037 for (i = 0; i < size; i++) {
1038 if (i >= SZINT) { /* will throw away a byte? */ 1038 if (i >= SZINT) { /* will throw away a byte? */
1039 /* check for overflow: it is OK to throw away leading zeros for a 1039 /* check for overflow: it is OK to throw away leading zeros for a
1040 positive number; leading ones for a negative number; and one 1040 positive number, leading ones for a negative number, and a
1041 last leading zero to allow unsigned integers with a 1 in 1041 leading zero byte to allow unsigned integers with a 1 in
1042 its "signal bit" */ 1042 its "signal bit" */
1043 if (!((n & HIGHERBYTE1) == 0 || /* zeros for pos. number */ 1043 if (!((n & HIGHERBYTE1) == 0 || /* zeros for positive number */
1044 (n & HIGHERBYTE1) == HIGHERBYTE1 || /* ones for neg. number */ 1044 (n & HIGHERBYTE1) == HIGHERBYTE1 || /* ones for negative number */
1045 ((n & HIGHERBYTE) == 0 && i == size - 1))) /* last zero */ 1045 ((n & HIGHERBYTE) == 0 && i == size - 1))) /* leading zero */
1046 return 0; /* overflow */ 1046 return 0; /* overflow */
1047 } 1047 }
1048 n <<= NB; 1048 n <<= NB;