aboutsummaryrefslogtreecommitdiff
path: root/lundump.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-11-10 12:35:48 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-11-10 12:35:48 -0300
commit3b57e37e4821ddce4756428956b7e9f4969efa4c (patch)
treea0bd071341349d964d98f55e7c2be8860792ff1f /lundump.c
parent024f9064f1b43758eb36aba52547edc0312bf4ba (diff)
downloadlua-3b57e37e4821ddce4756428956b7e9f4969efa4c.tar.gz
lua-3b57e37e4821ddce4756428956b7e9f4969efa4c.tar.bz2
lua-3b57e37e4821ddce4756428956b7e9f4969efa4c.zip
Fixed buffers save long strings as external.
Diffstat (limited to 'lundump.c')
-rw-r--r--lundump.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/lundump.c b/lundump.c
index 5b4cd2ea..09752d99 100644
--- a/lundump.c
+++ b/lundump.c
@@ -147,17 +147,24 @@ static TString *loadStringN (LoadState *S, Proto *p) {
147 luaH_getint(S->h, idx, &stv); 147 luaH_getint(S->h, idx, &stv);
148 return tsvalue(&stv); 148 return tsvalue(&stv);
149 } 149 }
150 else if (size -= 2, size <= LUAI_MAXSHORTLEN) { /* short string? */ 150 else if ((size -= 2) <= LUAI_MAXSHORTLEN) { /* short string? */
151 char buff[LUAI_MAXSHORTLEN]; 151 char buff[LUAI_MAXSHORTLEN + 1]; /* extra space for '\0' */
152 loadVector(S, buff, size); /* load string into buffer */ 152 loadVector(S, buff, size + 1); /* load string into buffer */
153 ts = luaS_newlstr(L, buff, size); /* create string */ 153 ts = luaS_newlstr(L, buff, size); /* create string */
154 } 154 }
155 else { /* long string */ 155 else { /* long string */
156 ts = luaS_createlngstrobj(L, size); /* create string */ 156 if (S->fixed) { /* for a fixed buffer, use a fixed string */
157 setsvalue2s(L, L->top.p, ts); /* anchor it ('loadVector' can GC) */ 157 const char *s = getaddr(S, size + 1, char); /* get content address */
158 luaD_inctop(L); 158 ts = luaS_newextlstr(L, s, size, NULL, NULL);
159 loadVector(S, getlngstr(ts), size); /* load directly in final place */ 159 }
160 L->top.p--; /* pop string */ 160 else { /* create internal copy */
161 ts = luaS_createlngstrobj(L, size); /* create string */
162 setsvalue2s(L, L->top.p, ts); /* anchor it ('loadVector' can GC) */
163 luaD_inctop(L);
164 loadVector(S, getlngstr(ts), size); /* load directly in final place */
165 loadByte(S); /* skip ending '\0' */
166 L->top.p--; /* pop string */
167 }
161 } 168 }
162 luaC_objbarrier(L, p, ts); 169 luaC_objbarrier(L, p, ts);
163 S->nstr++; /* add string to list of saved strings */ 170 S->nstr++; /* add string to list of saved strings */