aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lj_bcread.c3
-rw-r--r--src/lj_lex.c5
-rw-r--r--src/lj_lex.h1
3 files changed, 8 insertions, 1 deletions
diff --git a/src/lj_bcread.c b/src/lj_bcread.c
index 6a462bd6..62695ef4 100644
--- a/src/lj_bcread.c
+++ b/src/lj_bcread.c
@@ -80,6 +80,7 @@ static LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need)
80 ls->current = -1; /* Only bad if we get called again. */ 80 ls->current = -1; /* Only bad if we get called again. */
81 break; 81 break;
82 } 82 }
83 if (size >= LJ_MAX_MEM - ls->sb.n) lj_err_mem(ls->L);
83 if (ls->sb.n) { /* Append to buffer. */ 84 if (ls->sb.n) { /* Append to buffer. */
84 MSize n = ls->sb.n + (MSize)size; 85 MSize n = ls->sb.n + (MSize)size;
85 bcread_resize(ls, n < len ? len : n); 86 bcread_resize(ls, n < len ? len : n);
@@ -467,7 +468,7 @@ GCproto *lj_bcread(LexState *ls)
467 setprotoV(L, L->top, pt); 468 setprotoV(L, L->top, pt);
468 incr_top(L); 469 incr_top(L);
469 } 470 }
470 if ((int32_t)ls->n > 0 || L->top-1 != bcread_oldtop(L, ls)) 471 if ((ls->n && !ls->endmark) || L->top-1 != bcread_oldtop(L, ls))
471 bcread_error(ls, LJ_ERR_BCBAD); 472 bcread_error(ls, LJ_ERR_BCBAD);
472 /* Pop off last prototype. */ 473 /* Pop off last prototype. */
473 L->top--; 474 L->top--;
diff --git a/src/lj_lex.c b/src/lj_lex.c
index 1d063f8f..ecfcc015 100644
--- a/src/lj_lex.c
+++ b/src/lj_lex.c
@@ -49,6 +49,10 @@ static int fillbuf(LexState *ls)
49 size_t sz; 49 size_t sz;
50 const char *buf = ls->rfunc(ls->L, ls->rdata, &sz); 50 const char *buf = ls->rfunc(ls->L, ls->rdata, &sz);
51 if (buf == NULL || sz == 0) return END_OF_STREAM; 51 if (buf == NULL || sz == 0) return END_OF_STREAM;
52 if (sz >= LJ_MAX_MEM) {
53 if (sz != ~(size_t)0) lj_err_mem(ls->L);
54 ls->endmark = 1;
55 }
52 ls->n = (MSize)sz - 1; 56 ls->n = (MSize)sz - 1;
53 ls->p = buf; 57 ls->p = buf;
54 return char2int(*(ls->p++)); 58 return char2int(*(ls->p++));
@@ -382,6 +386,7 @@ int lj_lex_setup(lua_State *L, LexState *ls)
382 ls->lookahead = TK_eof; /* No look-ahead token. */ 386 ls->lookahead = TK_eof; /* No look-ahead token. */
383 ls->linenumber = 1; 387 ls->linenumber = 1;
384 ls->lastline = 1; 388 ls->lastline = 1;
389 ls->endmark = 0;
385 lj_str_resizebuf(ls->L, &ls->sb, LJ_MIN_SBUF); 390 lj_str_resizebuf(ls->L, &ls->sb, LJ_MIN_SBUF);
386 next(ls); /* Read-ahead first char. */ 391 next(ls); /* Read-ahead first char. */
387 if (ls->current == 0xef && ls->n >= 2 && char2int(ls->p[0]) == 0xbb && 392 if (ls->current == 0xef && ls->n >= 2 && char2int(ls->p[0]) == 0xbb &&
diff --git a/src/lj_lex.h b/src/lj_lex.h
index 41c03f93..f2346593 100644
--- a/src/lj_lex.h
+++ b/src/lj_lex.h
@@ -72,6 +72,7 @@ typedef struct LexState {
72 BCInsLine *bcstack; /* Stack for bytecode instructions/line numbers. */ 72 BCInsLine *bcstack; /* Stack for bytecode instructions/line numbers. */
73 MSize sizebcstack; /* Size of bytecode stack. */ 73 MSize sizebcstack; /* Size of bytecode stack. */
74 uint32_t level; /* Syntactical nesting level. */ 74 uint32_t level; /* Syntactical nesting level. */
75 int endmark; /* Trust bytecode end marker, even if not at EOF. */
75} LexState; 76} LexState;
76 77
77LJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls); 78LJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls);