diff options
Diffstat (limited to 'lmem.c')
-rw-r--r-- | lmem.c | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.c,v 1.28 2000/03/10 18:37:44 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.29 2000/03/16 20:35:07 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -88,6 +88,7 @@ static void *debug_realloc (void *block, size_t size) { | |||
88 | size_t realsize = HEADER+size+MARKSIZE; | 88 | size_t realsize = HEADER+size+MARKSIZE; |
89 | char *newblock = (char *)(malloc)(realsize); /* alloc a new block */ | 89 | char *newblock = (char *)(malloc)(realsize); /* alloc a new block */ |
90 | int i; | 90 | int i; |
91 | if (realsize < size) return NULL; /* overflow! */ | ||
91 | if (newblock == NULL) return NULL; | 92 | if (newblock == NULL) return NULL; |
92 | if (block) { | 93 | if (block) { |
93 | size_t oldsize = *blocksize(block); | 94 | size_t oldsize = *blocksize(block); |
@@ -111,10 +112,10 @@ static void *debug_realloc (void *block, size_t size) { | |||
111 | 112 | ||
112 | 113 | ||
113 | 114 | ||
114 | void *luaM_growaux (lua_State *L, void *block, unsigned long nelems, | 115 | void *luaM_growaux (lua_State *L, void *block, size_t nelems, |
115 | int inc, int size, const char *errormsg, unsigned long limit) { | 116 | int inc, size_t size, const char *errormsg, size_t limit) { |
116 | unsigned long newn = nelems+inc; | 117 | size_t newn = nelems+inc; |
117 | if (newn >= limit) lua_error(L, errormsg); | 118 | if (nelems >= limit-inc) lua_error(L, errormsg); |
118 | if ((newn ^ nelems) <= nelems || /* still the same power-of-2 limit? */ | 119 | if ((newn ^ nelems) <= nelems || /* still the same power-of-2 limit? */ |
119 | (nelems > 0 && newn < MINPOWER2)) /* or block already is MINPOWER2? */ | 120 | (nelems > 0 && newn < MINPOWER2)) /* or block already is MINPOWER2? */ |
120 | return block; /* do not need to reallocate */ | 121 | return block; /* do not need to reallocate */ |
@@ -126,12 +127,12 @@ void *luaM_growaux (lua_State *L, void *block, unsigned long nelems, | |||
126 | /* | 127 | /* |
127 | ** generic allocation routine. | 128 | ** generic allocation routine. |
128 | */ | 129 | */ |
129 | void *luaM_realloc (lua_State *L, void *block, unsigned long size) { | 130 | void *luaM_realloc (lua_State *L, void *block, lint32 size) { |
130 | if (size == 0) { | 131 | if (size == 0) { |
131 | free(block); /* block may be NULL; that is OK for free */ | 132 | free(block); /* block may be NULL; that is OK for free */ |
132 | return NULL; | 133 | return NULL; |
133 | } | 134 | } |
134 | else if ((size_t)size != size) | 135 | else if (size >= MAX_SIZET) |
135 | lua_error(L, "memory allocation error: block too big"); | 136 | lua_error(L, "memory allocation error: block too big"); |
136 | block = realloc(block, size); | 137 | block = realloc(block, size); |
137 | if (block == NULL) | 138 | if (block == NULL) |