diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2007-11-08 08:55:01 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2007-11-08 08:55:01 +0000 |
commit | d67c29302aeb3e4c4fbbadd0caeb5ce8209d76d2 (patch) | |
tree | 3adcb022425203f9b4896e6daf4e6fc7ffca5040 /apps | |
parent | a50a80e1a3bcff9e3c739d796605c10e1f8e8d05 (diff) | |
download | rockbox-d67c29302aeb3e4c4fbbadd0caeb5ce8209d76d2.tar.gz rockbox-d67c29302aeb3e4c4fbbadd0caeb5ce8209d76d2.zip |
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
Diffstat (limited to 'apps')
-rw-r--r-- | apps/codecs/Tremor/oggmalloc.c | 16 |
1 files changed, 10 insertions, 6 deletions
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 <os_types.h> 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]; } |