Browse Source

new constant 'MAX_SIZE', distinct from 'MAX_SIZET', for sizes visible

from Lua; these must fit in a lua_Integer
pull/9/head
Roberto Ierusalimschy 12 years ago
parent
commit
130c0e40e0
  1. 4
      llex.c
  2. 8
      llimits.h
  3. 6
      lstring.c
  4. 4
      lvm.c

4
llex.c

@ -1,5 +1,5 @@
/*
** $Id: llex.c,v 2.65 2013/04/26 13:07:53 roberto Exp roberto $
** $Id: llex.c,v 2.66 2013/05/14 15:59:04 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -53,7 +53,7 @@ static void save (LexState *ls, int c) {
Mbuffer *b = ls->buff;
if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) {
size_t newsize;
if (luaZ_sizebuffer(b) >= MAX_SIZET/2)
if (luaZ_sizebuffer(b) >= MAX_SIZE/2)
lexerror(ls, "lexical element too long", 0);
newsize = luaZ_sizebuffer(b) * 2;
luaZ_resizebuffer(ls->L, b, newsize);

8
llimits.h

@ -1,5 +1,5 @@
/*
** $Id: llimits.h,v 1.106 2013/05/27 12:43:37 roberto Exp roberto $
** $Id: llimits.h,v 1.107 2013/05/29 14:04:15 roberto Exp roberto $
** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h
*/
@ -27,8 +27,14 @@ typedef LUAI_MEM l_mem;
typedef unsigned char lu_byte;
/* maximum value for size_t */
#define MAX_SIZET ((size_t)(~(size_t)0)-2)
/* maximum size visible for Lua (must be representable in a lua_Integer */
#define MAX_SIZE (sizeof(size_t) <= sizeof(lua_Integer) ? MAX_SIZET \
: (size_t)(~(lua_Unsigned)0)-2)
#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
#define MAX_LMEM ((l_mem) ((MAX_LUMEM >> 1) - 2))

6
lstring.c

@ -1,5 +1,5 @@
/*
** $Id: lstring.c,v 2.25 2012/10/02 17:41:50 roberto Exp roberto $
** $Id: lstring.c,v 2.26 2013/01/08 13:50:10 roberto Exp roberto $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@ -157,7 +157,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
if (l <= LUAI_MAXSHORTLEN) /* short string? */
return internshrstr(L, str, l);
else {
if (l + 1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
if (l + 1 > (MAX_SIZE - sizeof(TString))/sizeof(char))
luaM_toobig(L);
return createstrobj(L, str, l, LUA_TLNGSTR, G(L)->seed, NULL);
}
@ -174,7 +174,7 @@ TString *luaS_new (lua_State *L, const char *str) {
Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {
Udata *u;
if (s > MAX_SIZET - sizeof(Udata))
if (s > MAX_SIZE - sizeof(Udata))
luaM_toobig(L);
u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, NULL, 0)->u;
u->uv.len = s;

4
lvm.c

@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 2.172 2013/06/04 19:36:42 roberto Exp roberto $
** $Id: lvm.c,v 2.173 2013/06/07 19:02:05 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -284,7 +284,7 @@ void luaV_concat (lua_State *L, int total) {
/* collect total length */
for (i = 1; i < total && tostring(L, top-i-1); i++) {
size_t l = tsvalue(top-i-1)->len;
if (l >= (MAX_SIZET/sizeof(char)) - tl)
if (l >= (MAX_SIZE/sizeof(char)) - tl)
luaG_runerror(L, "string length overflow");
tl += l;
}

Loading…
Cancel
Save