From 318d82e14fc968a03814193e52fda5b1b0c28851 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 8 May 2023 16:49:33 +0200 Subject: [PATCH] alsa: avoid division by 0 After we se the format, we negotiate the buffer size and period size. When this fails, the period_size can be 0. Handle this case without causing a floating point exception. --- spa/plugins/alsa/alsa-pcm-sink.c | 3 ++- spa/plugins/alsa/alsa-pcm-source.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm-sink.c b/spa/plugins/alsa/alsa-pcm-sink.c index 639fd46d9..249d5db4a 100644 --- a/spa/plugins/alsa/alsa-pcm-sink.c +++ b/spa/plugins/alsa/alsa-pcm-sink.c @@ -47,7 +47,8 @@ static void emit_node_info(struct state *this, bool full) items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_NODE_MAX_LATENCY, latency); snprintf(period, sizeof(period), "%lu", this->period_frames); items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-size", period); - snprintf(nperiods, sizeof(nperiods), "%lu", this->buffer_frames / this->period_frames); + snprintf(nperiods, sizeof(nperiods), "%lu", + this->period_frames != 0 ? this->buffer_frames / this->period_frames : 0); items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-num", nperiods); snprintf(headroom, sizeof(headroom), "%u", this->headroom); items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.headroom", headroom); diff --git a/spa/plugins/alsa/alsa-pcm-source.c b/spa/plugins/alsa/alsa-pcm-source.c index 59cdaae0f..2867c901a 100644 --- a/spa/plugins/alsa/alsa-pcm-source.c +++ b/spa/plugins/alsa/alsa-pcm-source.c @@ -49,7 +49,8 @@ static void emit_node_info(struct state *this, bool full) items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_NODE_MAX_LATENCY, latency); snprintf(period, sizeof(period), "%lu", this->period_frames); items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-size", period); - snprintf(nperiods, sizeof(nperiods), "%lu", this->buffer_frames / this->period_frames); + snprintf(nperiods, sizeof(nperiods), "%lu", + this->period_frames != 0 ? this->buffer_frames / this->period_frames : 0); items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-num", nperiods); snprintf(headroom, sizeof(headroom), "%u", this->headroom); items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.headroom", headroom);