comparison src/xs_stil.c @ 635:dcd9d179e217

The reallocation function was buggy and subtune entries were not being stored at all, fixed.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 03 Sep 2007 23:10:02 +0000
parents d7389ea52113
children a8ceae9ae8e3
comparison
equal deleted inserted replaced
634:a50428d6cc49 635:dcd9d179e217
34 { 34 {
35 if (!pNode) return FALSE; 35 if (!pNode) return FALSE;
36 36
37 /* Re-allocate subTune structure if needed */ 37 /* Re-allocate subTune structure if needed */
38 if (nsubTunes > pNode->nsubTunes) { 38 if (nsubTunes > pNode->nsubTunes) {
39 gint clearIndex, clearLength;
40
39 pNode->subTunes = 41 pNode->subTunes =
40 (t_xs_stil_subnode **) g_realloc(pNode->subTunes, 42 (t_xs_stil_subnode **) g_realloc(pNode->subTunes,
41 (nsubTunes + 1) * sizeof(t_xs_stil_subnode **)); 43 (nsubTunes + 1) * sizeof(t_xs_stil_subnode **));
42 44
43 if (!pNode->subTunes) { 45 if (!pNode->subTunes) {
44 xs_error(_("SubTune pointer structure realloc failed.\n")); 46 xs_error(_("SubTune pointer structure realloc failed.\n"));
45 return FALSE; 47 return FALSE;
46 } 48 }
47 49
48 /* Clear the newly allocated memory */ 50 /* Clear the newly allocated memory */
49 xs_memset(&(pNode->subTunes[pNode->nsubTunes]), 0, 51 if (pNode->nsubTunes == 0) {
50 (nsubTunes - pNode->nsubTunes + 1) * sizeof(t_xs_stil_subnode **)); 52 clearIndex = 0;
53 clearLength = nsubTunes + 1;
54 } else {
55 clearIndex = pNode->nsubTunes + 1;
56 clearLength = (nsubTunes - clearIndex + 1);
57 }
58 xs_memset(&(pNode->subTunes[clearIndex]), 0, clearLength * sizeof(t_xs_stil_subnode **));
51 59
52 pNode->nsubTunes = nsubTunes; 60 pNode->nsubTunes = nsubTunes;
53 } 61 }
54 62
55 /* Allocate memory for subTune */ 63 /* Allocate memory for subTune */
266 isError = TRUE; 274 isError = TRUE;
267 break; 275 break;
268 } 276 }
269 277
270 /* Some other type */ 278 /* Some other type */
271 if (strncmp(tmpLine, " NAME:", 8) == 0) { 279 if (strncmp(tmpLine, " NAME:", 8) == 0) {
272 XS_STILDB_MULTI; 280 XS_STILDB_MULTI;
273 g_free(tmpNode->subTunes[subEntry]->pName); 281 g_free(tmpNode->subTunes[subEntry]->pName);
274 tmpNode->subTunes[subEntry]->pName = g_strdup(&tmpLine[9]); 282 tmpNode->subTunes[subEntry]->pName = g_strdup(&tmpLine[9]);
275 } else if (strncmp(tmpLine, " TITLE:", 8) == 0) { 283 } else if (strncmp(tmpLine, " TITLE:", 8) == 0) {
276 XS_STILDB_MULTI; 284 XS_STILDB_MULTI;