summaryrefslogtreecommitdiff
path: root/lmem.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-12-01 13:46:18 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-12-01 13:46:18 -0200
commit97e2dab1fb1b90f806eeb4da51bb74a2cdb6ca54 (patch)
tree197e23df4a3f31910b6269cf9cfd574caa2a318d /lmem.c
parent0ed85191270f8bbe3ef7c4f5f0466de89b00c9b5 (diff)
downloadlua-github-97e2dab1fb1b90f806eeb4da51bb74a2cdb6ca54.tar.gz
better control of overflows in size computations
Diffstat (limited to 'lmem.c')
-rw-r--r--lmem.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/lmem.c b/lmem.c
index 29252abe..f2a70d0f 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmem.c,v 1.65 2004/08/30 13:44:44 roberto Exp roberto $
+** $Id: lmem.c,v 1.66 2004/11/19 15:52:40 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -43,16 +43,14 @@
#define MINSIZEARRAY 4
-void *luaM_growaux (lua_State *L, void *block, int *size, size_t size_elems,
- int limit, const char *errormsg) {
+void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
+ int limit, const char *errormsg) {
void *newblock;
int newsize;
- if (cast(size_t, limit) > MAX_SIZET/size_elems)
- limit = cast(int, MAX_SIZET/size_elems);
if (*size >= limit/2) { /* cannot double it? */
- if (*size >= limit - MINSIZEARRAY) /* try something smaller... */
+ if (*size >= limit) /* cannot grow even a little? */
luaG_runerror(L, errormsg);
- newsize = limit; /* still have at least MINSIZEARRAY free places */
+ newsize = limit; /* still have at least one free place */
}
else {
newsize = (*size)*2;
@@ -75,7 +73,7 @@ void *luaM_toobig (lua_State *L) {
/*
** generic allocation routine.
*/
-void *luaM_realloc (lua_State *L, void *block, size_t osize, size_t nsize) {
+void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
global_State *g = G(L);
lua_assert((osize == 0) == (block == NULL));
block = (*g->realloc)(g->ud, block, osize, nsize);