aboutsummaryrefslogtreecommitdiff
path: root/lmem.h
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.h
parent0ed85191270f8bbe3ef7c4f5f0466de89b00c9b5 (diff)
downloadlua-97e2dab1fb1b90f806eeb4da51bb74a2cdb6ca54.tar.gz
lua-97e2dab1fb1b90f806eeb4da51bb74a2cdb6ca54.tar.bz2
lua-97e2dab1fb1b90f806eeb4da51bb74a2cdb6ca54.zip
better control of overflows in size computations
Diffstat (limited to 'lmem.h')
-rw-r--r--lmem.h22
1 files changed, 11 insertions, 11 deletions
diff --git a/lmem.h b/lmem.h
index 514cccfd..331d722f 100644
--- a/lmem.h
+++ b/lmem.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.h,v 1.27 2004/11/19 15:52:40 roberto Exp roberto $ 2** $Id: lmem.h,v 1.28 2004/11/24 19:20:21 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*/
@@ -16,31 +16,31 @@
16#define MEMERRMSG "not enough memory" 16#define MEMERRMSG "not enough memory"
17 17
18 18
19void *luaM_realloc (lua_State *L, void *block, size_t oldsize, size_t size); 19void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, size_t size);
20 20
21void *luaM_toobig (lua_State *L); 21void *luaM_toobig (lua_State *L);
22 22
23#define luaM_reallocv(L,b,on,n,e) \ 23#define luaM_reallocv(L,b,on,n,e) \
24 ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 only to avoid warnings */ \ 24 ((cast(unsigned int, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \
25 luaM_realloc(L, (b), (on)*(e), (n)*(e)) : \ 25 luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
26 luaM_toobig(L)) 26 luaM_toobig(L))
27 27
28 28
29void *luaM_growaux (lua_State *L, void *block, int *size, size_t size_elem, 29void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elem,
30 int limit, const char *errormsg); 30 int limit, const char *errormsg);
31 31
32#define luaM_freemem(L, b, s) luaM_realloc(L, (b), (s), 0) 32#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
33#define luaM_free(L, b) luaM_realloc(L, (b), sizeof(*(b)), 0) 33#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
34#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) 34#define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t))
35 35
36#define luaM_malloc(L,t) luaM_realloc(L, NULL, 0, (t)) 36#define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t))
37#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 37#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
38#define luaM_newvector(L,n,t) \ 38#define luaM_newvector(L,n,t) \
39 cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 39 cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
40 40
41#define luaM_growvector(L,v,nelems,size,t,limit,e) \ 41#define luaM_growvector(L,v,nelems,size,t,limit,e) \
42 if (((nelems)+1) > (size)) \ 42 if ((nelems)+1 > (size)) \
43 ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e))) 43 ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
44 44
45#define luaM_reallocvector(L, v,oldn,n,t) \ 45#define luaM_reallocvector(L, v,oldn,n,t) \
46 ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 46 ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))