changeset 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 a50428d6cc49
children ea06356d792b
files src/xs_stil.c
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/xs_stil.c	Mon Sep 03 05:43:03 2007 +0000
+++ b/src/xs_stil.c	Mon Sep 03 23:10:02 2007 +0000
@@ -36,6 +36,8 @@
 
 	/* Re-allocate subTune structure if needed */
 	if (nsubTunes > pNode->nsubTunes) {
+		gint clearIndex, clearLength;
+		
 		pNode->subTunes =
 			(t_xs_stil_subnode **) g_realloc(pNode->subTunes,
 			(nsubTunes + 1) * sizeof(t_xs_stil_subnode **));
@@ -46,8 +48,14 @@
 		}
 		
 		/* Clear the newly allocated memory */
-		xs_memset(&(pNode->subTunes[pNode->nsubTunes]), 0,
-		(nsubTunes - pNode->nsubTunes + 1) * sizeof(t_xs_stil_subnode **));
+		if (pNode->nsubTunes == 0) {
+			clearIndex = 0;
+			clearLength = nsubTunes + 1;
+		} else {
+			clearIndex = pNode->nsubTunes + 1;
+			clearLength = (nsubTunes - clearIndex + 1);
+		}
+		xs_memset(&(pNode->subTunes[clearIndex]), 0, clearLength * sizeof(t_xs_stil_subnode **));
 		
 		pNode->nsubTunes = nsubTunes;
 	}
@@ -268,7 +276,7 @@
 			}
 			
 			/* Some other type */
-			if (strncmp(tmpLine, " NAME:", 8) == 0) {
+			if (strncmp(tmpLine, "   NAME:", 8) == 0) {
 				XS_STILDB_MULTI;
 				g_free(tmpNode->subTunes[subEntry]->pName);
 				tmpNode->subTunes[subEntry]->pName = g_strdup(&tmpLine[9]);