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; }