Index: src/XMPPSRVEnumerator.m ================================================================== --- src/XMPPSRVEnumerator.m +++ src/XMPPSRVEnumerator.m @@ -319,11 +319,11 @@ - (id)nextObject { XMPPSRVEntry *ret; of_list_object_t *iter; uint32_t totalWeight = 0; - BOOL found = NO; + BOOL loop = YES; if (done) return nil; if (listIter == NULL) @@ -333,18 +333,20 @@ return nil; if (subListCopy == nil) subListCopy = [listIter->object copy]; - /* FIXME: Handle empty subListCopy */ for (iter = [subListCopy firstListObject]; iter != NULL; iter = iter->next) { totalWeight += [iter->object weight]; [iter->object setAccumulatedWeight: totalWeight]; } - while (!found) { + if ([subListCopy count] == 0) + loop = NO; + + while (loop) { uint32_t randomWeight; RAND_pseudo_bytes((uint8_t*)&randomWeight, sizeof(uint32_t)); randomWeight %= (totalWeight + 1); @@ -353,11 +355,11 @@ if ([iter->object accumulatedWeight] >= randomWeight) { ret = [[iter->object retain] autorelease]; [subListCopy removeListObject: iter]; - found = YES; + loop = NO; break; } } }