Mercurial > audlegacy-plugins
comparison src/madplug/input.c @ 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 | 4ad6e7dfb389 |
children | 2d7b190acc76 |
comparison
equal
deleted
inserted
replaced
2467:13f021d53367 | 2468:615b67c4e010 |
---|---|
187 *(ret + ret_len) = 0; //terminate | 187 *(ret + ret_len) = 0; //terminate |
188 ptr = end + 1; | 188 ptr = end + 1; |
189 } | 189 } |
190 else if (ptr <= tail && *ptr != 0) { | 190 else if (ptr <= tail && *ptr != 0) { |
191 // reference to an id3v1 genre code | 191 // reference to an id3v1 genre code |
192 for(end = ptr; *end != ')' && *end != 0;) { | 192 for(tmp_len = 0, end = ptr; *end != ')' && *end != 0;) { |
193 end++; | 193 end++; |
194 tmp_len++; | |
194 } | 195 } |
195 | 196 |
196 tmp = g_malloc0(BYTES(end - ptr + 1)); | 197 tmp = g_malloc0(BYTES(tmp_len + 1)); |
197 memcpy(tmp, ptr, BYTES(end - ptr)); | 198 memcpy(tmp, ptr, BYTES(tmp_len)); |
198 *(tmp + (end - ptr)) = 0; //terminate | 199 *(tmp + tmp_len) = 0; //terminate |
199 ptr += end - ptr; | 200 ptr += tmp_len; |
200 | 201 |
201 genre = (id3_ucs4_t *)id3_genre_name((const id3_ucs4_t *)tmp); | 202 genre = (id3_ucs4_t *)id3_genre_name((const id3_ucs4_t *)tmp); |
202 | 203 |
203 g_free(tmp); | 204 g_free(tmp); |
204 tmp = NULL; | 205 tmp = NULL; |
205 | 206 |
206 tmp_len = mad_ucs4len(genre); | 207 if (genre) { |
207 | 208 tmp_len = mad_ucs4len(genre); |
208 memcpy(ret + ret_len, genre, BYTES(tmp_len)); | 209 memcpy(ret + ret_len, genre, BYTES(tmp_len)); |
209 | 210 ret_len += tmp_len; |
210 ret_len += tmp_len; | 211 } |
211 *(ret + ret_len) = 0; //terminate | 212 *(ret + ret_len) = 0; //terminate |
212 } | 213 } |
213 } | 214 } |
214 else { | 215 else { |
215 for(end = ptr; *end != '(' && *end != 0; ) { | 216 for(end = ptr; *end != '(' && *end != 0; ) { |
226 tp++; | 227 tp++; |
227 } | 228 } |
228 | 229 |
229 if(is_num) { | 230 if(is_num) { |
230 AUDDBG("is_num!\n"); | 231 AUDDBG("is_num!\n"); |
231 | 232 tmp_len = end - ptr; |
232 tmp = g_malloc0(BYTES(end - ptr + 1)); | 233 tmp = g_malloc0(BYTES(tmp_len + 1)); |
233 memcpy(tmp, ptr, BYTES(end - ptr)); | 234 memcpy(tmp, ptr, BYTES(tmp_len)); |
234 *(tmp + (end - ptr)) = 0; //terminate | 235 *(tmp + tmp_len) = 0; //terminate |
235 ptr += end - ptr; | 236 ptr += tmp_len; |
236 | 237 |
237 genre = (id3_ucs4_t *)id3_genre_name((const id3_ucs4_t *)tmp); | 238 genre = (id3_ucs4_t *)id3_genre_name((const id3_ucs4_t *)tmp); |
238 AUDDBG("genre length = %d\n", mad_ucs4len(genre)); | 239 AUDDBG("genre length = %d\n", mad_ucs4len(genre)); |
239 | 240 |
240 g_free(tmp); | 241 g_free(tmp); |
241 tmp = NULL; | 242 tmp = NULL; |
242 | 243 |
243 tmp_len = mad_ucs4len(genre); | 244 if (genre) { |
244 | 245 tmp_len = mad_ucs4len(genre); |
245 memcpy(ret + ret_len, genre, BYTES(tmp_len)); | 246 memcpy(ret + ret_len, genre, BYTES(tmp_len)); |
246 | 247 ret_len += tmp_len; |
247 ret_len += tmp_len; | 248 } |
248 *(ret + ret_len) = 0; //terminate | 249 *(ret + ret_len) = 0; //terminate |
249 } | 250 } |
250 else { // plain text | 251 else { // plain text |
252 tmp_len = end - ptr; | |
251 AUDDBG("plain!\n"); | 253 AUDDBG("plain!\n"); |
252 AUDDBG("ret_len = %d\n", ret_len); | 254 AUDDBG("ret_len = %d\n", ret_len); |
253 AUDDBG("end - ptr = %d\n", BYTES(end - ptr)); | 255 AUDDBG("end - ptr = %d\n", BYTES(tmp_len)); |
254 | 256 |
255 memcpy(ret + ret_len, ptr, BYTES(end - ptr)); | 257 memcpy(ret + ret_len, ptr, BYTES(tmp_len)); |
256 ret_len = ret_len + (end - ptr); | 258 ret_len = ret_len + tmp_len; |
257 *(ret + ret_len) = 0; //terminate | 259 *(ret + ret_len) = 0; //terminate |
258 ptr += (end - ptr); | 260 ptr += tmp_len; |
259 } | 261 } |
260 } | 262 } |
261 } | 263 } |
262 return ret; | 264 return ret; |
263 } | 265 } |