diff options
Diffstat (limited to 'src/lj_bcread.c')
-rw-r--r-- | src/lj_bcread.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/lj_bcread.c b/src/lj_bcread.c index 48c5e7c7..27d5d04a 100644 --- a/src/lj_bcread.c +++ b/src/lj_bcread.c | |||
@@ -73,6 +73,7 @@ static LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need) | |||
73 | ls->c = -1; /* Only bad if we get called again. */ | 73 | ls->c = -1; /* Only bad if we get called again. */ |
74 | break; | 74 | break; |
75 | } | 75 | } |
76 | if (sz >= LJ_MAX_BUF - n) lj_err_mem(ls->L); | ||
76 | if (n) { /* Append to buffer. */ | 77 | if (n) { /* Append to buffer. */ |
77 | n += (MSize)sz; | 78 | n += (MSize)sz; |
78 | p = lj_buf_need(&ls->sb, n < len ? len : n); | 79 | p = lj_buf_need(&ls->sb, n < len ? len : n); |
@@ -84,20 +85,20 @@ static LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need) | |||
84 | ls->p = buf; | 85 | ls->p = buf; |
85 | ls->pe = buf + sz; | 86 | ls->pe = buf + sz; |
86 | } | 87 | } |
87 | } while (ls->p + len > ls->pe); | 88 | } while ((MSize)(ls->pe - ls->p) < len); |
88 | } | 89 | } |
89 | 90 | ||
90 | /* Need a certain number of bytes. */ | 91 | /* Need a certain number of bytes. */ |
91 | static LJ_AINLINE void bcread_need(LexState *ls, MSize len) | 92 | static LJ_AINLINE void bcread_need(LexState *ls, MSize len) |
92 | { | 93 | { |
93 | if (LJ_UNLIKELY(ls->p + len > ls->pe)) | 94 | if (LJ_UNLIKELY((MSize)(ls->pe - ls->p) < len)) |
94 | bcread_fill(ls, len, 1); | 95 | bcread_fill(ls, len, 1); |
95 | } | 96 | } |
96 | 97 | ||
97 | /* Want to read up to a certain number of bytes, but may need less. */ | 98 | /* Want to read up to a certain number of bytes, but may need less. */ |
98 | static LJ_AINLINE void bcread_want(LexState *ls, MSize len) | 99 | static LJ_AINLINE void bcread_want(LexState *ls, MSize len) |
99 | { | 100 | { |
100 | if (LJ_UNLIKELY(ls->p + len > ls->pe)) | 101 | if (LJ_UNLIKELY((MSize)(ls->pe - ls->p) < len)) |
101 | bcread_fill(ls, len, 0); | 102 | bcread_fill(ls, len, 0); |
102 | } | 103 | } |
103 | 104 | ||
@@ -447,8 +448,7 @@ GCproto *lj_bcread(LexState *ls) | |||
447 | setprotoV(L, L->top, pt); | 448 | setprotoV(L, L->top, pt); |
448 | incr_top(L); | 449 | incr_top(L); |
449 | } | 450 | } |
450 | if ((int32_t)(2*(uint32_t)(ls->pe - ls->p)) > 0 || | 451 | if ((ls->pe != ls->p && !ls->endmark) || L->top-1 != bcread_oldtop(L, ls)) |
451 | L->top-1 != bcread_oldtop(L, ls)) | ||
452 | bcread_error(ls, LJ_ERR_BCBAD); | 452 | bcread_error(ls, LJ_ERR_BCBAD); |
453 | /* Pop off last prototype. */ | 453 | /* Pop off last prototype. */ |
454 | L->top--; | 454 | L->top--; |