Mercurial > audlegacy-plugins
changeset 2468:615b67c4e010
Tiny cleanups of repetitive code syndrome madness; Added some null-pointer checks.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 29 Mar 2008 12:06:38 +0200 |
parents | 13f021d53367 |
children | 2d7b190acc76 |
files | src/madplug/input.c |
diffstat | 1 files changed, 28 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/madplug/input.c Sat Mar 29 11:28:11 2008 +0200 +++ b/src/madplug/input.c Sat Mar 29 12:06:38 2008 +0200 @@ -189,25 +189,26 @@ } else if (ptr <= tail && *ptr != 0) { // reference to an id3v1 genre code - for(end = ptr; *end != ')' && *end != 0;) { + for(tmp_len = 0, end = ptr; *end != ')' && *end != 0;) { end++; + tmp_len++; } - tmp = g_malloc0(BYTES(end - ptr + 1)); - memcpy(tmp, ptr, BYTES(end - ptr)); - *(tmp + (end - ptr)) = 0; //terminate - ptr += end - ptr; + tmp = g_malloc0(BYTES(tmp_len + 1)); + memcpy(tmp, ptr, BYTES(tmp_len)); + *(tmp + tmp_len) = 0; //terminate + ptr += tmp_len; genre = (id3_ucs4_t *)id3_genre_name((const id3_ucs4_t *)tmp); g_free(tmp); tmp = NULL; - - tmp_len = mad_ucs4len(genre); - - memcpy(ret + ret_len, genre, BYTES(tmp_len)); - - ret_len += tmp_len; + + if (genre) { + tmp_len = mad_ucs4len(genre); + memcpy(ret + ret_len, genre, BYTES(tmp_len)); + ret_len += tmp_len; + } *(ret + ret_len) = 0; //terminate } } @@ -228,34 +229,35 @@ if(is_num) { AUDDBG("is_num!\n"); - - tmp = g_malloc0(BYTES(end - ptr + 1)); - memcpy(tmp, ptr, BYTES(end - ptr)); - *(tmp + (end - ptr)) = 0; //terminate - ptr += end - ptr; + tmp_len = end - ptr; + tmp = g_malloc0(BYTES(tmp_len + 1)); + memcpy(tmp, ptr, BYTES(tmp_len)); + *(tmp + tmp_len) = 0; //terminate + ptr += tmp_len; genre = (id3_ucs4_t *)id3_genre_name((const id3_ucs4_t *)tmp); AUDDBG("genre length = %d\n", mad_ucs4len(genre)); g_free(tmp); tmp = NULL; - - tmp_len = mad_ucs4len(genre); - - memcpy(ret + ret_len, genre, BYTES(tmp_len)); - - ret_len += tmp_len; + + if (genre) { + tmp_len = mad_ucs4len(genre); + memcpy(ret + ret_len, genre, BYTES(tmp_len)); + ret_len += tmp_len; + } *(ret + ret_len) = 0; //terminate } else { // plain text + tmp_len = end - ptr; AUDDBG("plain!\n"); AUDDBG("ret_len = %d\n", ret_len); - AUDDBG("end - ptr = %d\n", BYTES(end - ptr)); + AUDDBG("end - ptr = %d\n", BYTES(tmp_len)); - memcpy(ret + ret_len, ptr, BYTES(end - ptr)); - ret_len = ret_len + (end - ptr); + memcpy(ret + ret_len, ptr, BYTES(tmp_len)); + ret_len = ret_len + tmp_len; *(ret + ret_len) = 0; //terminate - ptr += (end - ptr); + ptr += tmp_len; } } }