LADI
/
spa
1
Fork 0

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.
This commit is contained in:
Wim Taymans 2023-05-08 16:49:33 +02:00
parent d2cd65b6e2
commit 318d82e14f
2 changed files with 4 additions and 2 deletions

View File

@ -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);

View File

@ -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);