better treatment for arbitrary limits

This commit is contained in:
Roberto Ierusalimschy 1999-06-17 14:04:03 -03:00
parent d4dce57f5c
commit 36b6fe8d17
8 changed files with 56 additions and 34 deletions

4
lapi.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 1.44 1999/05/11 20:08:20 roberto Exp roberto $
** $Id: lapi.c,v 1.45 1999/05/14 12:24:20 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -632,7 +632,7 @@ char *lua_getobjname (lua_Object o, char **name)
#ifndef MAX_C_BLOCKS
#define MAX_C_BLOCKS 1000
#define MAX_C_BLOCKS 1000 /* arbitrary limit */
#endif

View File

@ -1,5 +1,5 @@
/*
** $Id: lbuiltin.c,v 1.57 1999/05/24 17:53:49 roberto Exp roberto $
** $Id: lbuiltin.c,v 1.58 1999/05/27 20:21:03 roberto Exp roberto $
** Built-in functions
** See Copyright Notice in lua.h
*/
@ -111,7 +111,10 @@ static void error_message (void) {
** model but changing "fputs" to put the strings at a proper place
** (a console window or a log file, for instance).
*/
#define MAXPRINT 40
#ifndef MAXPRINT
#define MAXPRINT 40 /* arbitrary limit */
#endif
static void luaB_print (void) {
lua_Object args[MAXPRINT];
lua_Object obj;

4
ldo.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 1.42 1999/05/10 13:54:01 roberto Exp roberto $
** $Id: ldo.c,v 1.43 1999/05/24 17:53:03 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -29,7 +29,7 @@
#ifndef STACK_LIMIT
#define STACK_LIMIT 6000
#define STACK_LIMIT 6000 /* arbitrary limit */
#endif

6
llex.c
View File

@ -1,5 +1,5 @@
/*
** $Id: llex.c,v 1.34 1999/03/25 21:05:05 roberto Exp roberto $
** $Id: llex.c,v 1.35 1999/05/14 12:24:04 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -106,7 +106,9 @@ void luaX_setinput (LexState *LS, ZIO *z)
** =======================================================
*/
#define PRAGMASIZE 80
#ifndef PRAGMASIZE
#define PRAGMASIZE 80 /* arbitrary limit */
#endif
static void skipspace (LexState *LS) {
while (LS->current == ' ' || LS->current == '\t' || LS->current == '\r')

6
llex.h
View File

@ -1,5 +1,5 @@
/*
** $Id: llex.h,v 1.10 1998/07/24 18:02:38 roberto Exp roberto $
** $Id: llex.h,v 1.11 1999/02/25 19:13:56 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -25,7 +25,9 @@ enum RESERVED {
NAME, CONC, DOTS, EQ, GE, LE, NE, NUMBER, STRING, EOS};
#define MAX_IFS 5
#ifndef MAX_IFS
#define MAX_IFS 5 /* arbitrary limit */
#endif
/* "ifstate" keeps the state of each nested $if the lexical is dealing with. */

View File

@ -1,5 +1,5 @@
/*
** $Id: lopcodes.h,v 1.31 1999/03/05 21:16:07 roberto Exp roberto $
** $Id: lopcodes.h,v 1.32 1999/03/10 14:09:45 roberto Exp roberto $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -113,7 +113,7 @@ CHECKSTACK /* b (assert #temporaries == b; only for internal debuging!) */
#define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */
#define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) */
#define ZEROVARARG 64
#define ZEROVARARG 128
/* maximum value of an arg of 3 bytes; must fit in an "int" */

View File

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 1.35 1999/06/16 13:22:04 roberto Exp roberto $
** $Id: lparser.c,v 1.36 1999/06/16 13:35:01 roberto Exp roberto $
** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h
*/
@ -22,26 +22,32 @@
#include "lzio.h"
/* for limit numbers in error messages */
#define MES_LIM(x) "(limit=" x ")"
/* size of a "normal" jump instruction: OpCode + 1 byte */
#define JMPSIZE 2
/* maximum number of local variables */
#define MAXLOCALS 200
#define SMAXLOCALS "200"
#ifndef MAXLOCALS
#define MAXLOCALS 200 /* arbitrary limit (<256) */
#endif
/* maximum number of upvalues */
#define MAXUPVALUES 32
#define SMAXUPVALUES "32"
#ifndef MAXUPVALUES
#define MAXUPVALUES 32 /* arbitrary limit (<256) */
#endif
/* maximum number of variables in the left side of an assignment */
#define MAXVARSLH 100
#define SMAXVARSLH "100"
#ifndef MAXVARSLH
#define MAXVARSLH 100 /* arbitrary limit (<255) */
#endif
/* maximum number of parameters in a function */
#ifndef MAXPARAMS
#define MAXPARAMS 100 /* arbitrary limit (<ZEROVARARG) */
#endif
/*
@ -136,6 +142,15 @@ static void var_or_func_tail (LexState *ls, vardesc *v);
static void checklimit (LexState *ls, int val, int limit, char *msg) {
if (val > limit) {
char buff[100];
sprintf(buff, "too many %s (limit=%d)", msg, limit);
luaX_error(ls, buff);
}
}
static void check_pc (FuncState *fs, int n) {
luaM_growvector(fs->f->code, fs->pc, n, Byte, codeEM, MAX_INT);
}
@ -310,8 +325,7 @@ static void luaI_unregisterlocalvar (FuncState *fs, int line) {
static void store_localvar (LexState *ls, TaggedString *name, int n) {
FuncState *fs = ls->fs;
if (fs->nlocalvar+n >= MAXLOCALS)
luaX_error(ls, "too many local variables " MES_LIM(SMAXLOCALS));
checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables");
fs->localvar[fs->nlocalvar+n] = name;
luaI_registerlocalvar(fs, name, ls->linenumber);
}
@ -369,9 +383,8 @@ static int indexupvalue (LexState *ls, TaggedString *n) {
return i;
}
/* new one */
if (++(fs->nupvalues) > MAXUPVALUES)
luaX_error(ls, "too many upvalues in a single function "
MES_LIM(SMAXUPVALUES));
++(fs->nupvalues);
checklimit(ls, fs->nupvalues, MAXUPVALUES, "upvalues");
fs->upvalues[i] = v; /* i = fs->nupvalues - 1 */
return i;
}
@ -439,6 +452,7 @@ static void adjust_mult_assign (LexState *ls, int nvars, listdesc *d) {
static void code_args (LexState *ls, int nparams, int dots) {
FuncState *fs = ls->fs;
fs->nlocalvar += nparams; /* "self" may already be there */
checklimit(ls, fs->nlocalvar, MAXPARAMS, "parameters");
nparams = fs->nlocalvar;
if (!dots) {
fs->f->code[1] = (Byte)nparams; /* fill-in arg information */
@ -917,7 +931,7 @@ static int priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6};
static OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP, LTOP,
LEOP, GEOP, CONCOP, ADDOP, SUBOP, MULTOP, DIVOP, POWOP};
#define MAXOPS 20 /* op's stack size */
#define MAXOPS 20 /* op's stack size (arbitrary limit) */
typedef struct stack_op {
int ops[MAXOPS];
@ -1226,9 +1240,7 @@ static void decinit (LexState *ls, listdesc *d) {
static int assignment (LexState *ls, vardesc *v, int nvars) {
int left = 0;
if (nvars > MAXVARSLH)
luaX_error(ls, "too many variables in a multiple assignment "
MES_LIM(SMAXVARSLH));
checklimit(ls, nvars, MAXVARSLH, "variables in a multiple assignment");
unloaddot(ls, v);
if (ls->token == ',') { /* assignment -> ',' NAME assignment */
vardesc nv;

View File

@ -1,5 +1,5 @@
/*
** $Id: lstrlib.c,v 1.30 1999/05/05 19:22:26 roberto Exp roberto $
** $Id: lstrlib.c,v 1.31 1999/05/14 12:24:04 roberto Exp roberto $
** Standard library for strings and pattern-matching
** See Copyright Notice in lua.h
*/
@ -117,7 +117,10 @@ static void str_char (void) {
** =======================================================
*/
#define MAX_CAPT 32
#ifndef MAX_CAPT
#define MAX_CAPT 32 /* arbitrary limit */
#endif
struct Capture {
char *src_end; /* end ('\0') of source string */
@ -499,7 +502,7 @@ static void luaI_addquoted (int arg) {
}
/* maximum size of each format specification (such as '%-099.99d') */
#define MAX_FORMAT 20
#define MAX_FORMAT 20 /* arbitrary limit */
static void str_format (void) {
int arg = 1;