[alsa-devel] [PATCH TINYCOMPRESS 13/14] compress: Prevent divide-by-zero faults in get_hpointer()

Richard Fitzgerald rf at opensource.wolfsonmicro.com
Sun Feb 10 01:22:16 CET 2013


Do not assume that the returned snd_compr_avail contains a
snd_compr_tstamp with a valid sampling_rate. Check for zero
before attempting to use it.

diff --git a/compress.c b/compress.c
index cfd0219..c0e81a3 100644
--- a/compress.c
+++ b/compress.c
@@ -297,10 +297,15 @@ int compress_get_hpointer(struct compress *compress,
 	if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &kavail))
 		return oops(compress, errno, "cannot get avail");
 	*avail = (unsigned int)kavail.avail;
-	time = kavail.tstamp.pcm_io_frames / kavail.tstamp.sampling_rate;
-	tstamp->tv_sec = time;
-	time = kavail.tstamp.pcm_io_frames % kavail.tstamp.sampling_rate;
-	tstamp->tv_nsec = time * 1000000000 / kavail.tstamp.sampling_rate;
+	if (kavail.tstamp.sampling_rate != 0) {
+		time = kavail.tstamp.pcm_io_frames / kavail.tstamp.sampling_rate;
+		tstamp->tv_sec = time;
+		time = kavail.tstamp.pcm_io_frames % kavail.tstamp.sampling_rate;
+		tstamp->tv_nsec = time * 1000000000 / kavail.tstamp.sampling_rate;
+	} else {
+		tstamp->tv_sec = 0;
+		tstamp->tv_nsec = 0;
+	}
 	return 0;
 }
 
-- 
1.7.2.5




More information about the Alsa-devel mailing list