summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-11-08 08:55:01 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-11-08 08:55:01 +0000
commitd67c29302aeb3e4c4fbbadd0caeb5ce8209d76d2 (patch)
tree3adcb022425203f9b4896e6daf4e6fc7ffca5040 /apps
parenta50a80e1a3bcff9e3c739d796605c10e1f8e8d05 (diff)
downloadrockbox-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.c16
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 @@
1#include <os_types.h> 1#include <os_types.h>
2 2
3static unsigned char *mallocbuf; 3static unsigned char *mallocbuf;
4static long bufsize, tmp_ptr, mem_ptr; 4static size_t bufsize, tmp_ptr, mem_ptr;
5 5
6void ogg_malloc_init(void) 6void ogg_malloc_init(void)
7{ 7{
8 mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize); 8 mallocbuf = ci->get_codec_memory(&bufsize);
9 tmp_ptr = bufsize & ~3; 9 tmp_ptr = bufsize & ~3;
10 mem_ptr = 0; 10 mem_ptr = 0;
11} 11}
@@ -14,21 +14,25 @@ void *ogg_malloc(size_t size)
14{ 14{
15 void* x; 15 void* x;
16 16
17 if (mem_ptr + (long)size > tmp_ptr) 17 size = (size + 3) & ~3;
18
19 if (mem_ptr + size > tmp_ptr)
18 return NULL; 20 return NULL;
19 21
20 x = &mallocbuf[mem_ptr]; 22 x = &mallocbuf[mem_ptr];
21 mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */ 23 mem_ptr += size; /* Keep memory 32-bit aligned */
22 24
23 return x; 25 return x;
24} 26}
25 27
26void *ogg_tmpmalloc(size_t size) 28void *ogg_tmpmalloc(size_t size)
27{ 29{
28 if (mem_ptr + (long)size > tmp_ptr) 30 size = (size + 3) & ~3;
31
32 if (mem_ptr + size > tmp_ptr)
29 return NULL; 33 return NULL;
30 34
31 tmp_ptr -= (size + 3) & ~3; 35 tmp_ptr -= size;
32 return &mallocbuf[tmp_ptr]; 36 return &mallocbuf[tmp_ptr];
33} 37}
34 38