Correctly handle an empty priority list.
It should not exist, but this is no reason to not terminate.
This commit is contained in:
parent
18ec0d947b
commit
a04917a128
1 changed files with 6 additions and 4 deletions
|
@ -321,7 +321,7 @@
|
||||||
XMPPSRVEntry *ret;
|
XMPPSRVEntry *ret;
|
||||||
of_list_object_t *iter;
|
of_list_object_t *iter;
|
||||||
uint32_t totalWeight = 0;
|
uint32_t totalWeight = 0;
|
||||||
BOOL found = NO;
|
BOOL loop = YES;
|
||||||
|
|
||||||
if (done)
|
if (done)
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -335,14 +335,16 @@
|
||||||
if (subListCopy == nil)
|
if (subListCopy == nil)
|
||||||
subListCopy = [listIter->object copy];
|
subListCopy = [listIter->object copy];
|
||||||
|
|
||||||
/* FIXME: Handle empty subListCopy */
|
|
||||||
for (iter = [subListCopy firstListObject]; iter != NULL;
|
for (iter = [subListCopy firstListObject]; iter != NULL;
|
||||||
iter = iter->next) {
|
iter = iter->next) {
|
||||||
totalWeight += [iter->object weight];
|
totalWeight += [iter->object weight];
|
||||||
[iter->object setAccumulatedWeight: totalWeight];
|
[iter->object setAccumulatedWeight: totalWeight];
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!found) {
|
if ([subListCopy count] == 0)
|
||||||
|
loop = NO;
|
||||||
|
|
||||||
|
while (loop) {
|
||||||
uint32_t randomWeight;
|
uint32_t randomWeight;
|
||||||
|
|
||||||
RAND_pseudo_bytes((uint8_t*)&randomWeight, sizeof(uint32_t));
|
RAND_pseudo_bytes((uint8_t*)&randomWeight, sizeof(uint32_t));
|
||||||
|
@ -355,7 +357,7 @@
|
||||||
|
|
||||||
[subListCopy removeListObject: iter];
|
[subListCopy removeListObject: iter];
|
||||||
|
|
||||||
found = YES;
|
loop = NO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue