mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	make iterating with pa_idxset_next() robust in regards to idxset modifications
This commit is contained in:
		
							parent
							
								
									f8190be2e6
								
							
						
					
					
						commit
						c61ad2a706
					
				
					 1 changed files with 34 additions and 10 deletions
				
			
		| 
						 | 
					@ -386,8 +386,11 @@ void* pa_idxset_steal_first(pa_idxset *s, uint32_t *idx) {
 | 
				
			||||||
void* pa_idxset_first(pa_idxset *s, uint32_t *idx) {
 | 
					void* pa_idxset_first(pa_idxset *s, uint32_t *idx) {
 | 
				
			||||||
    pa_assert(s);
 | 
					    pa_assert(s);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!s->iterate_list_head)
 | 
					    if (!s->iterate_list_head) {
 | 
				
			||||||
 | 
					        if (idx)
 | 
				
			||||||
 | 
					            *idx = PA_IDXSET_INVALID;
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (idx)
 | 
					    if (idx)
 | 
				
			||||||
        *idx = s->iterate_list_head->idx;
 | 
					        *idx = s->iterate_list_head->idx;
 | 
				
			||||||
| 
						 | 
					@ -402,20 +405,41 @@ void *pa_idxset_next(pa_idxset *s, uint32_t *idx) {
 | 
				
			||||||
    pa_assert(s);
 | 
					    pa_assert(s);
 | 
				
			||||||
    pa_assert(idx);
 | 
					    pa_assert(idx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    hash = *idx % NBUCKETS;
 | 
					    if (*idx == PA_IDXSET_INVALID)
 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (!(e = index_scan(s, hash, *idx)))
 | 
					 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!e->iterate_next) {
 | 
					    hash = *idx % NBUCKETS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ((e = index_scan(s, hash, *idx))) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        e = e->iterate_next;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (e) {
 | 
				
			||||||
 | 
					            *idx = e->idx;
 | 
				
			||||||
 | 
					            return e->data;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
            *idx = PA_IDXSET_INVALID;
 | 
					            *idx = PA_IDXSET_INVALID;
 | 
				
			||||||
            return NULL;
 | 
					            return NULL;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    e = e->iterate_next;
 | 
					    } else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* If the entry passed doesn't exist anymore we try to find
 | 
				
			||||||
 | 
					         * the next following */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for ((*idx)++; *idx < s->current_index; (*idx)++) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            hash = *idx % NBUCKETS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if ((e = index_scan(s, hash, *idx))) {
 | 
				
			||||||
                *idx = e->idx;
 | 
					                *idx = e->idx;
 | 
				
			||||||
                return e->data;
 | 
					                return e->data;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        *idx = PA_IDXSET_INVALID;
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsigned pa_idxset_size(pa_idxset*s) {
 | 
					unsigned pa_idxset_size(pa_idxset*s) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue