hdspmixer: Fix ALSA snd_ctl_open error when running with three cards.

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>
This commit is contained in:
Adrian Knoth 2011-02-24 21:33:30 +01:00 committed by Takashi Iwai
parent 3506d3d9a7
commit 97e96addff
3 changed files with 9 additions and 7 deletions

View file

@ -219,7 +219,7 @@ static void restore_defaults_cb(Fl_Widget *widget, void *arg)
snprintf(w->window_title, FL_PATH_MAX, "HDSPMixer"); snprintf(w->window_title, FL_PATH_MAX, "HDSPMixer");
w->label(w->window_title); w->label(w->window_title);
w->resetMixer(); w->resetMixer();
while (w->cards[i] != NULL) { while (i < MAX_CARDS && w->cards[i] != NULL) {
w->restoreDefaults(i++); w->restoreDefaults(i++);
} }
w->inputs->buttons->presets->preset_change(1); w->inputs->buttons->presets->preset_change(1);
@ -408,7 +408,7 @@ void HDSPMixerWindow::load()
if ((file = fopen(file_name, "r")) == NULL) { if ((file = fopen(file_name, "r")) == NULL) {
int i = 0; int i = 0;
fl_alert("Error opening file %s for reading", file_name); fl_alert("Error opening file %s for reading", file_name);
while (cards[i] != NULL) { while (i < MAX_CARDS && cards[i] != NULL) {
restoreDefaults(i++); restoreDefaults(i++);
} }
inputs->buttons->presets->preset_change(1); 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); setup = new HDSPMixerSetup(400, 260, "Level Meters Setup", this);
about = new HDSPMixerAbout(360, 300, "About HDSPMixer", this); about = new HDSPMixerAbout(360, 300, "About HDSPMixer", this);
i = 0; i = 0;
while (cards[i] != NULL) { while (i < MAX_CARDS && cards[i] != NULL) {
cards[i++]->initializeCard(this); cards[i++]->initializeCard(this);
} }
size_range(MIN_WIDTH, MIN_HEIGHT, cards[current_card]->window_width, cards[current_card]->window_height); 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 { } else {
printf("Initializing default presets\n"); printf("Initializing default presets\n");
i = 0; i = 0;
while (cards[i] != NULL) { while (i < MAX_CARDS && cards[i] != NULL) {
restoreDefaults(i++); restoreDefaults(i++);
} }
inputs->buttons->presets->preset_change(1); 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_handler(handler_cb);
Fl::add_timeout(0.030, readregisters_cb, this); Fl::add_timeout(0.030, readregisters_cb, this);
i = 0; i = 0;
while (cards[i] != NULL) while (i < MAX_CARDS && cards[i] != NULL)
inputs->buttons->cardselector->ActivateCard (i++); inputs->buttons->cardselector->ActivateCard (i++);
} }

View file

@ -73,8 +73,8 @@ public:
Fl_Scroll *scroll; Fl_Scroll *scroll;
HDSPMixerSetup *setup; HDSPMixerSetup *setup;
HDSPMixerAbout *about; HDSPMixerAbout *about;
HDSPMixerPresetData *data[3][3][8]; /* data[card number][mode(ss/ds/qs)][preset number] */ HDSPMixerPresetData *data[MAX_CARDS][3][8]; /* data[card number][mode(ss/ds/qs)][preset number] */
HDSPMixerCard *cards[3]; HDSPMixerCard *cards[MAX_CARDS];
HDSPMixerInputs *inputs; HDSPMixerInputs *inputs;
HDSPMixerPlaybacks *playbacks; HDSPMixerPlaybacks *playbacks;
HDSPMixerOutputs *outputs; HDSPMixerOutputs *outputs;

View file

@ -47,6 +47,8 @@
#define PAN_WIDTH 28 #define PAN_WIDTH 28
#define MAX_CARDS 3
typedef unsigned long long int int64; typedef unsigned long long int int64;
#endif #endif