diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-08-20 15:15:23 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-08-20 15:15:23 -0300 |
commit | 75620b45ae9d500a3251a0e698de98ab588d2a29 (patch) | |
tree | 1b04673fe967d3849928f3bb4d39a7e9c6155bf6 | |
parent | 3e88b72b8e71c0946d089a04876e7bdc61d187a9 (diff) | |
download | lua-75620b45ae9d500a3251a0e698de98ab588d2a29.tar.gz lua-75620b45ae9d500a3251a0e698de98ab588d2a29.tar.bz2 lua-75620b45ae9d500a3251a0e698de98ab588d2a29.zip |
'lcode.c' can use 'checklimit', too
-rw-r--r-- | lcode.c | 10 | ||||
-rw-r--r-- | lparser.c | 10 | ||||
-rw-r--r-- | lparser.h | 2 |
3 files changed, 10 insertions, 12 deletions
@@ -208,8 +208,7 @@ void luaK_ret (FuncState *fs, int first, int nret) { | |||
208 | case 1: op = OP_RETURN1; break; | 208 | case 1: op = OP_RETURN1; break; |
209 | default: op = OP_RETURN; break; | 209 | default: op = OP_RETURN; break; |
210 | } | 210 | } |
211 | if (nret + 1 > MAXARG_B) | 211 | luaY_checklimit(fs, nret + 1, MAXARG_B, "returns"); |
212 | luaX_syntaxerror(fs->ls, "too many returns"); | ||
213 | luaK_codeABC(fs, op, first, nret + 1, 0); | 212 | luaK_codeABC(fs, op, first, nret + 1, 0); |
214 | } | 213 | } |
215 | 214 | ||
@@ -473,9 +472,7 @@ static int luaK_codek (FuncState *fs, int reg, int k) { | |||
473 | void luaK_checkstack (FuncState *fs, int n) { | 472 | void luaK_checkstack (FuncState *fs, int n) { |
474 | int newstack = fs->freereg + n; | 473 | int newstack = fs->freereg + n; |
475 | if (newstack > fs->f->maxstacksize) { | 474 | if (newstack > fs->f->maxstacksize) { |
476 | if (newstack > MAX_FSTACK) | 475 | luaY_checklimit(fs, newstack, MAX_FSTACK, "registers"); |
477 | luaX_syntaxerror(fs->ls, | ||
478 | "function or expression needs too many registers"); | ||
479 | fs->f->maxstacksize = cast_byte(newstack); | 476 | fs->f->maxstacksize = cast_byte(newstack); |
480 | } | 477 | } |
481 | } | 478 | } |
@@ -727,8 +724,7 @@ static void const2exp (TValue *v, expdesc *e) { | |||
727 | */ | 724 | */ |
728 | void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { | 725 | void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { |
729 | Instruction *pc = &getinstruction(fs, e); | 726 | Instruction *pc = &getinstruction(fs, e); |
730 | if (nresults + 1 > MAXARG_C) | 727 | luaY_checklimit(fs, nresults + 1, MAXARG_C, "multiple results"); |
731 | luaX_syntaxerror(fs->ls, "too many multiple results"); | ||
732 | if (e->k == VCALL) /* expression is an open function call? */ | 728 | if (e->k == VCALL) /* expression is an open function call? */ |
733 | SETARG_C(*pc, nresults + 1); | 729 | SETARG_C(*pc, nresults + 1); |
734 | else { | 730 | else { |
@@ -84,8 +84,8 @@ static l_noret errorlimit (FuncState *fs, int limit, const char *what) { | |||
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
87 | static void checklimit (FuncState *fs, int v, int l, const char *what) { | 87 | void luaY_checklimit (FuncState *fs, int v, int l, const char *what) { |
88 | if (v > l) errorlimit(fs, l, what); | 88 | if (l_unlikely(v > l)) errorlimit(fs, l, what); |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
@@ -196,7 +196,7 @@ static int new_localvarkind (LexState *ls, TString *name, lu_byte kind) { | |||
196 | FuncState *fs = ls->fs; | 196 | FuncState *fs = ls->fs; |
197 | Dyndata *dyd = ls->dyd; | 197 | Dyndata *dyd = ls->dyd; |
198 | Vardesc *var; | 198 | Vardesc *var; |
199 | checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal, | 199 | luaY_checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal, |
200 | MAXVARS, "local variables"); | 200 | MAXVARS, "local variables"); |
201 | luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1, | 201 | luaM_growvector(L, dyd->actvar.arr, dyd->actvar.n + 1, |
202 | dyd->actvar.size, Vardesc, USHRT_MAX, "local variables"); | 202 | dyd->actvar.size, Vardesc, USHRT_MAX, "local variables"); |
@@ -361,7 +361,7 @@ static int searchupvalue (FuncState *fs, TString *name) { | |||
361 | static Upvaldesc *allocupvalue (FuncState *fs) { | 361 | static Upvaldesc *allocupvalue (FuncState *fs) { |
362 | Proto *f = fs->f; | 362 | Proto *f = fs->f; |
363 | int oldsize = f->sizeupvalues; | 363 | int oldsize = f->sizeupvalues; |
364 | checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues"); | 364 | luaY_checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues"); |
365 | luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues, | 365 | luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues, |
366 | Upvaldesc, MAXUPVAL, "upvalues"); | 366 | Upvaldesc, MAXUPVAL, "upvalues"); |
367 | while (oldsize < f->sizeupvalues) | 367 | while (oldsize < f->sizeupvalues) |
@@ -860,7 +860,7 @@ static void recfield (LexState *ls, ConsControl *cc) { | |||
860 | lu_byte reg = ls->fs->freereg; | 860 | lu_byte reg = ls->fs->freereg; |
861 | expdesc tab, key, val; | 861 | expdesc tab, key, val; |
862 | if (ls->t.token == TK_NAME) { | 862 | if (ls->t.token == TK_NAME) { |
863 | checklimit(fs, cc->nh, INT_MAX, "items in a constructor"); | 863 | luaY_checklimit(fs, cc->nh, INT_MAX / 2, "items in a constructor"); |
864 | codename(ls, &key); | 864 | codename(ls, &key); |
865 | } | 865 | } |
866 | else /* ls->t.token == '[' */ | 866 | else /* ls->t.token == '[' */ |
@@ -164,6 +164,8 @@ typedef struct FuncState { | |||
164 | 164 | ||
165 | 165 | ||
166 | LUAI_FUNC lu_byte luaY_nvarstack (FuncState *fs); | 166 | LUAI_FUNC lu_byte luaY_nvarstack (FuncState *fs); |
167 | LUAI_FUNC void luaY_checklimit (FuncState *fs, int v, int l, | ||
168 | const char *what); | ||
167 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, | 169 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, |
168 | Dyndata *dyd, const char *name, int firstchar); | 170 | Dyndata *dyd, const char *name, int firstchar); |
169 | 171 | ||