mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	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:
		
							parent
							
								
									d2cd65b6e2
								
							
						
					
					
						commit
						318d82e14f
					
				
					 2 changed files with 4 additions and 2 deletions
				
			
		| 
						 | 
					@ -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);
 | 
								items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_NODE_MAX_LATENCY, latency);
 | 
				
			||||||
			snprintf(period, sizeof(period), "%lu", this->period_frames);
 | 
								snprintf(period, sizeof(period), "%lu", this->period_frames);
 | 
				
			||||||
			items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-size", period);
 | 
								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);
 | 
								items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-num", nperiods);
 | 
				
			||||||
			snprintf(headroom, sizeof(headroom), "%u", this->headroom);
 | 
								snprintf(headroom, sizeof(headroom), "%u", this->headroom);
 | 
				
			||||||
			items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.headroom", headroom);
 | 
								items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.headroom", headroom);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
								items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_NODE_MAX_LATENCY, latency);
 | 
				
			||||||
			snprintf(period, sizeof(period), "%lu", this->period_frames);
 | 
								snprintf(period, sizeof(period), "%lu", this->period_frames);
 | 
				
			||||||
			items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-size", period);
 | 
								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);
 | 
								items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.period-num", nperiods);
 | 
				
			||||||
			snprintf(headroom, sizeof(headroom), "%u", this->headroom);
 | 
								snprintf(headroom, sizeof(headroom), "%u", this->headroom);
 | 
				
			||||||
			items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.headroom", headroom);
 | 
								items[n_items++] = SPA_DICT_ITEM_INIT("api.alsa.headroom", headroom);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue