]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: handle start_treshold in snd_pcm_write_areas more robustly
authorJaroslav Kysela <perex@perex.cz>
Tue, 2 Jan 2024 10:16:26 +0000 (11:16 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 2 Jan 2024 10:20:05 +0000 (11:20 +0100)
The start_treshold is defined as unsigned, so fix the condition
to allow using values avobe LONG_MAX.

Also, fix the documentation for the 64-bit platforms (INTMAX -> LONG_MAX).

Fixes: https://github.com/alsa-project/alsa-lib/issues/374
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/pcm/pcm.c

index 75e81c03b115cc9ed554edc264d987e2048c5480..e8986ad897a0ac5d3e28be8011efd1b2d90fa15c 100644 (file)
@@ -378,7 +378,7 @@ be started automatically from the device. For capture, if the application wants
 to read count of samples equal or greater then the stream will be started.
 If you want to use explicit start (#snd_pcm_start), you can
 set this value greater than ring buffer size (in samples), but use the
-constant MAXINT is not a bad idea.
+constant LONG_MAX or the boundary value is not a bad idea.
 
 \par Stop threshold
 
@@ -7721,7 +7721,8 @@ snd_pcm_sframes_t snd_pcm_write_areas(snd_pcm_t *pcm, const snd_pcm_channel_area
                        /* some plugins might automatically start the stream */
                        state = __snd_pcm_state(pcm);
                        if (state == SND_PCM_STATE_PREPARED &&
-                           hw_avail >= (snd_pcm_sframes_t) pcm->start_threshold) {
+                           hw_avail >= 0 &&
+                           (snd_pcm_uframes_t) hw_avail >= pcm->start_threshold) {
                                err = __snd_pcm_start(pcm);
                                if (err < 0)
                                        goto _end;