File alsa-utils-speaker-test-parameter-get-fix.diff of Package alsa-utils

commit 0d6134450ea7db82128138c9ac1bc84e8696dce4
Author: Takashi Iwai <tiwai@suse.de>
Date:   Wed Nov 26 14:27:24 2008 +0100

    speaker-test: Fix floating-point exception bug
    
    The period_size an buffer_size parameters must be taken after calling
    snd_pcm_hw_params().  Otherwise they could be undefined numbers.
    For example, period_size gets 0 when pcsp driver is used, resulting in
    a floating-point exception error.
    
    Signed-off-by: Takashi Iwai <tiwai@suse.de>

diff --git a/speaker-test/speaker-test.c b/speaker-test/speaker-test.c
index d40342f..75a4bed 100644
--- a/speaker-test/speaker-test.c
+++ b/speaker-test/speaker-test.c
@@ -422,6 +422,14 @@ static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, snd_pcm_
       return err;
     }
   }
+
+  /* write the parameters to device */
+  err = snd_pcm_hw_params(handle, params);
+  if (err < 0) {
+    fprintf(stderr, _("Unable to set hw params for playback: %s\n"), snd_strerror(err));
+    return err;
+  }
+
   snd_pcm_hw_params_get_buffer_size(params, &buffer_size);
   snd_pcm_hw_params_get_period_size(params, &period_size, NULL);
   printf(_("was set period_size = %lu\n"),period_size);
@@ -431,13 +439,6 @@ static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, snd_pcm_
     return -EINVAL;
   }
 
-  /* write the parameters to device */
-  err = snd_pcm_hw_params(handle, params);
-  if (err < 0) {
-    fprintf(stderr, _("Unable to set hw params for playback: %s\n"), snd_strerror(err));
-    return err;
-  }
-
   return 0;
 }
openSUSE Build Service is sponsored by