From a04917a1289949bcc8ac54a88c0f232849a76e1e Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Thu, 26 May 2011 00:13:51 +0200 Subject: [PATCH] Correctly handle an empty priority list. It should not exist, but this is no reason to not terminate. --- src/XMPPSRVEnumerator.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/XMPPSRVEnumerator.m b/src/XMPPSRVEnumerator.m index 424f36d..385ea1a 100644 --- a/src/XMPPSRVEnumerator.m +++ b/src/XMPPSRVEnumerator.m @@ -321,7 +321,7 @@ XMPPSRVEntry *ret; of_list_object_t *iter; uint32_t totalWeight = 0; - BOOL found = NO; + BOOL loop = YES; if (done) return nil; @@ -335,14 +335,16 @@ 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)); @@ -355,7 +357,7 @@ [subListCopy removeListObject: iter]; - found = YES; + loop = NO; break; } }