diff options
Diffstat (limited to 'lundump.c')
| -rw-r--r-- | lundump.c | 21 |
1 files changed, 12 insertions, 9 deletions
| @@ -37,7 +37,7 @@ typedef struct { | |||
| 37 | const char *name; | 37 | const char *name; |
| 38 | Table *h; /* list for string reuse */ | 38 | Table *h; /* list for string reuse */ |
| 39 | size_t offset; /* current position relative to beginning of dump */ | 39 | size_t offset; /* current position relative to beginning of dump */ |
| 40 | lua_Integer nstr; /* number of strings in the list */ | 40 | lua_Unsigned nstr; /* number of strings in the list */ |
| 41 | lu_byte fixed; /* dump is fixed in memory */ | 41 | lu_byte fixed; /* dump is fixed in memory */ |
| 42 | } LoadState; | 42 | } LoadState; |
| 43 | 43 | ||
| @@ -94,8 +94,8 @@ static lu_byte loadByte (LoadState *S) { | |||
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | 96 | ||
| 97 | static size_t loadVarint (LoadState *S, size_t limit) { | 97 | static lua_Unsigned loadVarint (LoadState *S, lua_Unsigned limit) { |
| 98 | size_t x = 0; | 98 | lua_Unsigned x = 0; |
| 99 | int b; | 99 | int b; |
| 100 | limit >>= 7; | 100 | limit >>= 7; |
| 101 | do { | 101 | do { |
| @@ -127,9 +127,12 @@ static lua_Number loadNumber (LoadState *S) { | |||
| 127 | 127 | ||
| 128 | 128 | ||
| 129 | static lua_Integer loadInteger (LoadState *S) { | 129 | static lua_Integer loadInteger (LoadState *S) { |
| 130 | lua_Integer x; | 130 | lua_Unsigned cx = loadVarint(S, LUA_MAXUNSIGNED); |
| 131 | loadVar(S, x); | 131 | /* decode unsigned to signed */ |
| 132 | return x; | 132 | if ((cx & 1) != 0) |
| 133 | return l_castU2S(~(cx >> 1)); | ||
| 134 | else | ||
| 135 | return l_castU2S(cx >> 1); | ||
| 133 | } | 136 | } |
| 134 | 137 | ||
| 135 | 138 | ||
| @@ -149,9 +152,9 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { | |||
| 149 | return; | 152 | return; |
| 150 | } | 153 | } |
| 151 | else if (size == 1) { /* previously saved string? */ | 154 | else if (size == 1) { /* previously saved string? */ |
| 152 | lua_Integer idx = cast_st2S(loadSize(S)); /* get its index */ | 155 | lua_Unsigned idx = loadVarint(S, LUA_MAXUNSIGNED); /* get its index */ |
| 153 | TValue stv; | 156 | TValue stv; |
| 154 | luaH_getint(S->h, idx, &stv); /* get its value */ | 157 | luaH_getint(S->h, l_castU2S(idx), &stv); /* get its value */ |
| 155 | *sl = ts = tsvalue(&stv); | 158 | *sl = ts = tsvalue(&stv); |
| 156 | luaC_objbarrier(L, p, ts); | 159 | luaC_objbarrier(L, p, ts); |
| 157 | return; /* do not save it again */ | 160 | return; /* do not save it again */ |
| @@ -175,7 +178,7 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { | |||
| 175 | /* add string to list of saved strings */ | 178 | /* add string to list of saved strings */ |
| 176 | S->nstr++; | 179 | S->nstr++; |
| 177 | setsvalue(L, &sv, ts); | 180 | setsvalue(L, &sv, ts); |
| 178 | luaH_setint(L, S->h, S->nstr, &sv); | 181 | luaH_setint(L, S->h, l_castU2S(S->nstr), &sv); |
| 179 | luaC_objbarrierback(L, obj2gco(S->h), ts); | 182 | luaC_objbarrierback(L, obj2gco(S->h), ts); |
| 180 | } | 183 | } |
| 181 | 184 | ||
