diff options
Diffstat (limited to 'lstrlib.c')
| -rw-r--r-- | lstrlib.c | 15 |
1 files changed, 8 insertions, 7 deletions
| @@ -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 | ||
| 1040 | static int undumpint (const char *buff, lua_Integer *res, | 1040 | static 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 | ||
