diff options
author | Stefan Walter <stefw@src.gnome.org> | 2009-02-13 04:20:37 +0000 |
---|---|---|
committer | Stefan Walter <stefw@src.gnome.org> | 2009-02-13 04:20:37 +0000 |
commit | 94defe401c069030f36760212ee97215c328c259 (patch) | |
tree | 766752aaf2ab461ed37b7b02fcad28b1bd6f8578 /egg/egg-secure-memory.c | |
parent | 9b4111ad6c990f65f5119ed8d8edbee0f3adf19e (diff) | |
download | gnome-keyring-94defe401c069030f36760212ee97215c328c259.tar.gz |
Calculate memory header size at compile time.
svn path=/trunk/; revision=1559
Diffstat (limited to 'egg/egg-secure-memory.c')
-rw-r--r-- | egg/egg-secure-memory.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/egg/egg-secure-memory.c b/egg/egg-secure-memory.c index 481c361e..093db781 100644 --- a/egg/egg-secure-memory.c +++ b/egg/egg-secure-memory.c @@ -114,6 +114,7 @@ typedef size_t ref_t; /* suba offset from start of memory to object */ #define SREF(s,p) (ref_t)((char *)(p) - (char *)(s)) #define SADR(s,r) (void *)((char *)(s) + (r)) #define MINCELL 32 +#define HDRSIZ (ALIGN (sizeof *suba)) struct allocator { unsigned char magic[8]; /* suba header identifier */ @@ -131,7 +132,7 @@ struct cell { ref_t next; /* reference to next cell in free list */ }; -static void* +static inline void* suba_addr (const struct allocator *suba, const ref_t ref) { if (suba && ref > 0 && ref <= suba->size) { @@ -156,22 +157,19 @@ static struct allocator * suba_init (void *mem, size_t size) { struct allocator *suba = mem; - size_t hdrsiz; struct cell *c; - hdrsiz = ALIGN(sizeof *suba); - ASSERT (mem != NULL); - ASSERT (size > (hdrsiz + POFF)); - ASSERT (ALIGN (sizeof (*c)) >= MINCELL); + ASSERT (size > (HDRSIZ + POFF)); + ASSERT (ALIGN (sizeof (struct cell)) <= MINCELL); - memset(suba, 0, hdrsiz); + memset(suba, 0, HDRSIZ); memcpy(suba->magic, SUBA_MAGIC, 8); - suba->tail = hdrsiz; + suba->tail = HDRSIZ; suba->size = size; - c = suba_addr(suba, hdrsiz); - c->size = size - (hdrsiz + POFF); + c = suba_addr(suba, HDRSIZ); + c->size = size - (HDRSIZ + POFF); c->next = suba->tail; return suba; |