diff options
Diffstat (limited to 'lundump.c')
-rw-r--r-- | lundump.c | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -36,8 +36,8 @@ typedef struct { | |||
36 | ZIO *Z; | 36 | ZIO *Z; |
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 | lu_mem offset; /* current position relative to beginning of dump */ |
40 | lua_Unsigned nstr; /* number of strings in the list */ | 40 | lua_Integer 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,13 +94,13 @@ static lu_byte loadByte (LoadState *S) { | |||
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | static varint_t loadVarint (LoadState *S, varint_t limit) { | 97 | static size_t loadVarint (LoadState *S, size_t limit) { |
98 | varint_t x = 0; | 98 | size_t x = 0; |
99 | int b; | 99 | int b; |
100 | limit >>= 7; | 100 | limit >>= 7; |
101 | do { | 101 | do { |
102 | b = loadByte(S); | 102 | b = loadByte(S); |
103 | if (x >= limit) | 103 | if (x > limit) |
104 | error(S, "integer overflow"); | 104 | error(S, "integer overflow"); |
105 | x = (x << 7) | (b & 0x7f); | 105 | x = (x << 7) | (b & 0x7f); |
106 | } while ((b & 0x80) != 0); | 106 | } while ((b & 0x80) != 0); |
@@ -109,12 +109,12 @@ static varint_t loadVarint (LoadState *S, varint_t limit) { | |||
109 | 109 | ||
110 | 110 | ||
111 | static size_t loadSize (LoadState *S) { | 111 | static size_t loadSize (LoadState *S) { |
112 | return cast_sizet(loadVarint(S, MAX_SIZET)); | 112 | return loadVarint(S, MAX_SIZET); |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | static int loadInt (LoadState *S) { | 116 | static int loadInt (LoadState *S) { |
117 | return cast_int(loadVarint(S, INT_MAX)); | 117 | return cast_int(loadVarint(S, cast_sizet(INT_MAX))); |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
@@ -148,10 +148,9 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { | |||
148 | return; | 148 | return; |
149 | } | 149 | } |
150 | else if (size == 1) { /* previously saved string? */ | 150 | else if (size == 1) { /* previously saved string? */ |
151 | /* get its index */ | 151 | lua_Integer idx = cast(lua_Integer, loadSize(S)); /* get its index */ |
152 | lua_Unsigned idx = cast(lua_Unsigned, loadVarint(S, LUA_MAXUNSIGNED)); | ||
153 | TValue stv; | 152 | TValue stv; |
154 | luaH_getint(S->h, l_castU2S(idx), &stv); /* get its value */ | 153 | luaH_getint(S->h, idx, &stv); /* get its value */ |
155 | *sl = ts = tsvalue(&stv); | 154 | *sl = ts = tsvalue(&stv); |
156 | luaC_objbarrier(L, p, ts); | 155 | luaC_objbarrier(L, p, ts); |
157 | return; /* do not save it again */ | 156 | return; /* do not save it again */ |
@@ -175,7 +174,7 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { | |||
175 | /* add string to list of saved strings */ | 174 | /* add string to list of saved strings */ |
176 | S->nstr++; | 175 | S->nstr++; |
177 | setsvalue(L, &sv, ts); | 176 | setsvalue(L, &sv, ts); |
178 | luaH_setint(L, S->h, l_castU2S(S->nstr), &sv); | 177 | luaH_setint(L, S->h, S->nstr, &sv); |
179 | luaC_objbarrierback(L, obj2gco(S->h), ts); | 178 | luaC_objbarrierback(L, obj2gco(S->h), ts); |
180 | } | 179 | } |
181 | 180 | ||