From d67c29302aeb3e4c4fbbadd0caeb5ce8209d76d2 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 8 Nov 2007 08:55:01 +0000 Subject: Change oggmalloc.c to use size_t and kill a warning about type-punning. Align the size before checking out-of-mem so no overlap may occur between tmp and alloc. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15525 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/Tremor/oggmalloc.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'apps/codecs/Tremor') diff --git a/apps/codecs/Tremor/oggmalloc.c b/apps/codecs/Tremor/oggmalloc.c index eae3d3f1ee..d7e903b156 100644 --- a/apps/codecs/Tremor/oggmalloc.c +++ b/apps/codecs/Tremor/oggmalloc.c @@ -1,11 +1,11 @@ #include static unsigned char *mallocbuf; -static long bufsize, tmp_ptr, mem_ptr; +static size_t bufsize, tmp_ptr, mem_ptr; void ogg_malloc_init(void) { - mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize); + mallocbuf = ci->get_codec_memory(&bufsize); tmp_ptr = bufsize & ~3; mem_ptr = 0; } @@ -14,21 +14,25 @@ void *ogg_malloc(size_t size) { void* x; - if (mem_ptr + (long)size > tmp_ptr) + size = (size + 3) & ~3; + + if (mem_ptr + size > tmp_ptr) return NULL; x = &mallocbuf[mem_ptr]; - mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */ + mem_ptr += size; /* Keep memory 32-bit aligned */ return x; } void *ogg_tmpmalloc(size_t size) { - if (mem_ptr + (long)size > tmp_ptr) + size = (size + 3) & ~3; + + if (mem_ptr + size > tmp_ptr) return NULL; - tmp_ptr -= (size + 3) & ~3; + tmp_ptr -= size; return &mallocbuf[tmp_ptr]; } -- cgit v1.2.3