summaryrefslogtreecommitdiff
path: root/src/lstring.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lstring.c')
-rw-r--r--src/lstring.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lstring.c b/src/lstring.c
index 4c34dc9b..af2c6963 100644
--- a/src/lstring.c
+++ b/src/lstring.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstring.c,v 2.3 2004/08/24 20:12:06 roberto Exp $
+** $Id: lstring.c,v 2.5 2004/11/24 19:16:03 roberto Exp $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@@ -49,8 +49,11 @@ void luaS_resize (lua_State *L, int newsize) {
static TString *newlstr (lua_State *L, const char *str, size_t l,
unsigned int h) {
- TString *ts = cast(TString *, luaM_malloc(L, sizestring(l)));
+ TString *ts;
stringtable *tb;
+ if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
+ luaM_toobig(L);
+ ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString)));
ts->tsv.len = l;
ts->tsv.hash = h;
ts->tsv.marked = luaC_white(G(L));
@@ -75,7 +78,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
size_t l1;
for (l1=l; l1>=step; l1-=step) /* compute hash */
- h = h ^ ((h<<5)+(h>>2)+(unsigned char)(str[l1-1]));
+ h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
o != NULL;
o = o->gch.next) {
@@ -92,7 +95,9 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
Udata *luaS_newudata (lua_State *L, size_t s) {
Udata *u;
- u = cast(Udata *, luaM_malloc(L, sizeudata(s)));
+ if (s > MAX_SIZET - sizeof(Udata))
+ luaM_toobig(L);
+ u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata)));
u->uv.marked = luaC_white(G(L)); /* is not finalized */
u->uv.tt = LUA_TUSERDATA;
u->uv.len = s;