aboutsummaryrefslogtreecommitdiff
path: root/lundump.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-12-27 17:42:00 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-12-27 17:42:00 -0300
commite7af9cdf0b9fca080e8bb3463e16d60933e786f9 (patch)
treec008d59bd636afa37003326287487644b906229f /lundump.c
parent12b6f610b0f1b4157c04f0db264f1f1d0634709b (diff)
downloadlua-e7af9cdf0b9fca080e8bb3463e16d60933e786f9.tar.gz
lua-e7af9cdf0b9fca080e8bb3463e16d60933e786f9.tar.bz2
lua-e7af9cdf0b9fca080e8bb3463e16d60933e786f9.zip
Fixed buffers reuse absolute line information
Diffstat (limited to 'lundump.c')
-rw-r--r--lundump.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/lundump.c b/lundump.c
index f850dc4a..b33258b0 100644
--- a/lundump.c
+++ b/lundump.c
@@ -36,7 +36,7 @@ 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 lu_mem 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_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;
@@ -73,8 +73,10 @@ static void loadAlign (LoadState *S, int align) {
73 73
74#define getaddr(S,n,t) cast(t *, getaddr_(S,n,sizeof(t))) 74#define getaddr(S,n,t) cast(t *, getaddr_(S,n,sizeof(t)))
75 75
76static const void *getaddr_ (LoadState *S, int n, int sz) { 76static const void *getaddr_ (LoadState *S, int n, size_t sz) {
77 const void *block = luaZ_getaddr(S->Z, n * sz); 77 size_t size = n * sz;
78 const void *block = luaZ_getaddr(S->Z, size);
79 S->offset += size;
78 if (block == NULL) 80 if (block == NULL)
79 error(S, "truncated fixed buffer"); 81 error(S, "truncated fixed buffer");
80 return block; 82 return block;
@@ -143,7 +145,7 @@ static void loadString (LoadState *S, Proto *p, TString **sl) {
143 TValue sv; 145 TValue sv;
144 size_t size = loadSize(S); 146 size_t size = loadSize(S);
145 if (size == 0) { /* no string? */ 147 if (size == 0) { /* no string? */
146 *sl = NULL; 148 lua_assert(*sl == NULL); /* must be prefilled */
147 return; 149 return;
148 } 150 }
149 else if (size == 1) { /* previously saved string? */ 151 else if (size == 1) { /* previously saved string? */
@@ -287,11 +289,17 @@ static void loadDebug (LoadState *S, Proto *f) {
287 loadVector(S, f->lineinfo, n); 289 loadVector(S, f->lineinfo, n);
288 } 290 }
289 n = loadInt(S); 291 n = loadInt(S);
290 f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo); 292 if (n > 0) {
291 f->sizeabslineinfo = n; 293 loadAlign(S, sizeof(int));
292 for (i = 0; i < n; i++) { 294 if (S->fixed) {
293 f->abslineinfo[i].pc = loadInt(S); 295 f->abslineinfo = getaddr(S, n, AbsLineInfo);
294 f->abslineinfo[i].line = loadInt(S); 296 f->sizeabslineinfo = n;
297 }
298 else {
299 f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo);
300 f->sizeabslineinfo = n;
301 loadVector(S, f->abslineinfo, n);
302 }
295 } 303 }
296 n = loadInt(S); 304 n = loadInt(S);
297 f->locvars = luaM_newvectorchecked(S->L, n, LocVar); 305 f->locvars = luaM_newvectorchecked(S->L, n, LocVar);