changeset 621:11e24183ff23

Properly initialize xs_cfg struct; Check for 0 in sid2NFilterPresets.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 03 Sep 2007 00:21:05 +0000
parents 0f2b7b2556ff
children d7389ea52113
files src/xs_config.c
diffstat 1 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/xs_config.c	Sun Sep 02 23:09:05 2007 +0000
+++ b/src/xs_config.c	Mon Sep 03 00:21:05 2007 +0000
@@ -208,6 +208,8 @@
 	XSDEBUG("initializing configuration ...\n");
 	XS_MUTEX_LOCK(xs_cfg);
 
+	xs_memset(&xs_cfg, 0, sizeof(xs_cfg));
+	
 	/* Initialize values with sensible defaults */
 	xs_cfg.audioBitsPerSample = XS_RES_16BIT;
 	xs_cfg.audioChannels = XS_CHN_MONO;
@@ -238,6 +240,8 @@
 	xs_cfg.forceSpeed = FALSE;
 
 	xs_cfg.sid2OptLevel = 0;
+	xs_cfg.sid2NFilterPresets = 0;
+
 #ifdef HAVE_RESID_BUILDER
 	xs_cfg.sid2Builder = XS_BLD_RESID;
 #else
@@ -567,13 +571,15 @@
 	
 	/* Filters and presets are a special case */
 	xs_filter_load_into(cfg, 0, &xs_cfg.sid2Filter);
-	xs_cfg.sid2FilterPresets = g_malloc0(xs_cfg.sid2NFilterPresets * sizeof(t_xs_sid2_filter *));
-	if (!xs_cfg.sid2FilterPresets) {
-		xs_error(_("Allocation of sid2FilterPresets structure failed!\n"));
-	} else {
-		for (i = 0; i < xs_cfg.sid2NFilterPresets; i++) {
-			xs_cfg.sid2FilterPresets[i] =
-				xs_filter_load(cfg, i);
+	
+	if (xs_cfg.sid2NFilterPresets > 0) {
+		xs_cfg.sid2FilterPresets = g_malloc0(xs_cfg.sid2NFilterPresets * sizeof(t_xs_sid2_filter *));
+		if (!xs_cfg.sid2FilterPresets) {
+			xs_error(_("Allocation of sid2FilterPresets structure failed!\n"));
+		} else {
+			for (i = 0; i < xs_cfg.sid2NFilterPresets; i++) {
+				xs_cfg.sid2FilterPresets[i] = xs_filter_load(cfg, i);
+			}
 		}
 	}