diff options
-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 @@ | |||
1 | #include <os_types.h> | 1 | #include <os_types.h> |
2 | 2 | ||
3 | static unsigned char *mallocbuf; | 3 | static unsigned char *mallocbuf; |
4 | static long bufsize, tmp_ptr, mem_ptr; | 4 | static size_t bufsize, tmp_ptr, mem_ptr; |
5 | 5 | ||
6 | void ogg_malloc_init(void) | 6 | void 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 | ||
26 | void *ogg_tmpmalloc(size_t size) | 28 | void *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 | ||