diff options
author | Thomas Jarosch <tomj@simonv.com> | 2014-12-27 17:33:24 +0100 |
---|---|---|
committer | Thomas Jarosch <tomj@simonv.com> | 2014-12-27 17:33:24 +0100 |
commit | e7c282fed754bfc4a2fbdc2e8e1a7598b5fae27c (patch) | |
tree | b8b6f8d64597e75d5fd25a71734b2588748fec91 | |
parent | d68262eede9c5a5f911f9619784f466a6730e21a (diff) | |
download | rockbox-e7c282fed754bfc4a2fbdc2e8e1a7598b5fae27c.tar.gz rockbox-e7c282fed754bfc4a2fbdc2e8e1a7598b5fae27c.zip |
More standard conforming codec_realloc()
- Leave original ptr untouched if allocation fails
(bail out early)
- Behave like malloc() in case ptr is NULL
Change-Id: Ib854ca19bd0e069999b7780d2d9a533ece705add
-rw-r--r-- | lib/rbcodec/codecs/lib/codeclib.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/rbcodec/codecs/lib/codeclib.c b/lib/rbcodec/codecs/lib/codeclib.c index a12038eeb8..1f52c00434 100644 --- a/lib/rbcodec/codecs/lib/codeclib.c +++ b/lib/rbcodec/codecs/lib/codeclib.c | |||
@@ -91,8 +91,12 @@ void* codec_realloc(void* ptr, size_t size) | |||
91 | { | 91 | { |
92 | void* x; | 92 | void* x; |
93 | x = codec_malloc(size); | 93 | x = codec_malloc(size); |
94 | ci->memcpy(x, ptr, size); | 94 | if (x == NULL) |
95 | codec_free(ptr); | 95 | return NULL; |
96 | if (ptr) { | ||
97 | ci->memcpy(x, ptr, size); | ||
98 | codec_free(ptr); | ||
99 | } | ||
96 | return(x); | 100 | return(x); |
97 | } | 101 | } |
98 | 102 | ||