summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2012-04-23 15:00:03 (GMT)
committerRemko Tronçon <git@el-tramo.be>2012-04-23 15:00:37 (GMT)
commit00981790bc39e9a0674feec19ffa792329bb077c (patch)
tree1c623b82757c2a50cbc452b2cf85ae974ca79804
parentaed9957d22a4fa2e64df08a0e5ddfdbf309f130a (diff)
downloadswift-contrib-00981790bc39e9a0674feec19ffa792329bb077c.zip
swift-contrib-00981790bc39e9a0674feec19ffa792329bb077c.tar.bz2
Fixed assertion when SRV weights are all 0.
-rw-r--r--Swiften/Network/DomainNameServiceQuery.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/Swiften/Network/DomainNameServiceQuery.cpp b/Swiften/Network/DomainNameServiceQuery.cpp
index eb999e0..f7ffecc 100644
--- a/Swiften/Network/DomainNameServiceQuery.cpp
+++ b/Swiften/Network/DomainNameServiceQuery.cpp
@@ -46,19 +46,19 @@ void DomainNameServiceQuery::sortResults(std::vector<DomainNameServiceQuery::Res
ResultPriorityComparator comparator;
std::sort(queries.begin(), queries.end(), comparator);
std::vector<DomainNameServiceQuery::Result>::iterator i = queries.begin();
while (i != queries.end()) {
std::vector<DomainNameServiceQuery::Result>::iterator next = std::upper_bound(i, queries.end(), *i, comparator);
if (std::distance(i, next) > 1) {
int weightSum = std::accumulate(i, next, 0, WeightAccumulator());
std::vector<double> probabilities;
- std::transform(i, next, std::back_inserter(probabilities), WeightToProbability(weightSum));
+ std::transform(i, next, std::back_inserter(probabilities), WeightToProbability(weightSum > 0 ? weightSum : 1));
// Shuffling the result array and the probabilities in parallel
for (size_t j = 0; j < probabilities.size(); ++j) {
int selectedIndex = generator.generateWeighedRandomNumber(probabilities.begin() + j, probabilities.end());
std::swap(i[j], i[j + selectedIndex]);
std::swap(probabilities.begin()[j], probabilities.begin()[j + selectedIndex]);
}
}
i = next;