]> git.alsa-project.org Git - alsa-tools.git/commitdiff
hdspmixer: Fix ALSA snd_ctl_open error when running with three cards.
authorAdrian Knoth <adi@drcomp.erfurt.thur.de>
Thu, 24 Feb 2011 20:33:30 +0000 (21:33 +0100)
committerTakashi Iwai <tiwai@suse.de>
Mon, 28 Feb 2011 10:11:13 +0000 (11:11 +0100)
If three (or more) RME cards are installed in one box, hdspmixer will
try to open a non-existing 4th card, causing an error in snd_ctl_open
and finally terminates itself.

cards[] is a static array, and one must not read beyond the last
element. The solution is far from elegant, however, it's a rather
unintrusive change.

Signed-off-by: Adrian Knoth <adi@drcomp.erfurt.thur.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
hdspmixer/src/HDSPMixerWindow.cxx
hdspmixer/src/HDSPMixerWindow.h
hdspmixer/src/defines.h

index 38e7b612ac06de9077918efe0a46e82e50499457..a2e3db8a5664d3b19d3a2d2ed0a139613e30718f 100644 (file)
@@ -219,7 +219,7 @@ static void restore_defaults_cb(Fl_Widget *widget, void *arg)
     snprintf(w->window_title, FL_PATH_MAX, "HDSPMixer");
     w->label(w->window_title);
     w->resetMixer();
-    while (w->cards[i] != NULL) {
+    while (i < MAX_CARDS && w->cards[i] != NULL) {
        w->restoreDefaults(i++);
     }
     w->inputs->buttons->presets->preset_change(1);
@@ -408,7 +408,7 @@ void HDSPMixerWindow::load()
     if ((file = fopen(file_name, "r")) == NULL) {
        int i = 0;
        fl_alert("Error opening file %s for reading", file_name);
-       while (cards[i] != NULL) {
+       while (i < MAX_CARDS && cards[i] != NULL) {
            restoreDefaults(i++);
        }
        inputs->buttons->presets->preset_change(1);     
@@ -718,7 +718,7 @@ HDSPMixerWindow::HDSPMixerWindow(int x, int y, int w, int h, const char *label,
     setup = new HDSPMixerSetup(400, 260, "Level Meters Setup", this);
     about = new HDSPMixerAbout(360, 300, "About HDSPMixer", this);
     i = 0;
-    while (cards[i] != NULL) {
+    while (i < MAX_CARDS && cards[i] != NULL) {
        cards[i++]->initializeCard(this);
     }
     size_range(MIN_WIDTH, MIN_HEIGHT, cards[current_card]->window_width, cards[current_card]->window_height);
@@ -729,7 +729,7 @@ HDSPMixerWindow::HDSPMixerWindow(int x, int y, int w, int h, const char *label,
     } else {
        printf("Initializing default presets\n");
        i = 0;
-       while (cards[i] != NULL) {
+       while (i < MAX_CARDS && cards[i] != NULL) {
            restoreDefaults(i++);
        }
        inputs->buttons->presets->preset_change(1);
@@ -738,7 +738,7 @@ HDSPMixerWindow::HDSPMixerWindow(int x, int y, int w, int h, const char *label,
     Fl::add_handler(handler_cb);
     Fl::add_timeout(0.030, readregisters_cb, this);
     i = 0;
-    while (cards[i] != NULL)
+    while (i < MAX_CARDS && cards[i] != NULL)
       inputs->buttons->cardselector->ActivateCard (i++);
 }
 
index f10b729179d00913377dd283d4646dbf1f02244b..0eb6f1a9a0a23d891fc2eb6387215107a42cf2bd 100644 (file)
@@ -73,8 +73,8 @@ public:
     Fl_Scroll *scroll;
     HDSPMixerSetup *setup;
     HDSPMixerAbout *about;
-    HDSPMixerPresetData *data[3][3][8]; /* data[card number][mode(ss/ds/qs)][preset number] */
-    HDSPMixerCard *cards[3];
+    HDSPMixerPresetData *data[MAX_CARDS][3][8]; /* data[card number][mode(ss/ds/qs)][preset number] */
+    HDSPMixerCard *cards[MAX_CARDS];
     HDSPMixerInputs *inputs;
     HDSPMixerPlaybacks *playbacks;
     HDSPMixerOutputs *outputs;
index 20656209852643f8e5013a381133ed7a1a901ba3..d29c37c2769a28d8de50bd20a85b753078c044a7 100644 (file)
@@ -47,6 +47,8 @@
 
 #define PAN_WIDTH 28
 
+#define MAX_CARDS      3
+
 typedef unsigned long long int int64;
 
 #endif