fix endless loop bug
This commit is contained in:
parent
c9e6601607
commit
701d945371
|
@ -132,6 +132,10 @@
|
|||
var getPieceStatus = function (bitField, pieceCount) {
|
||||
var pieces = [];
|
||||
|
||||
for (var i = 0; i < pieceCount; i++) {
|
||||
pieces.push(false);
|
||||
}
|
||||
|
||||
if (!bitField) {
|
||||
return pieces;
|
||||
}
|
||||
|
@ -145,8 +149,7 @@
|
|||
var bit = (1 << (4 - j));
|
||||
var isCompleted = (bitSet & bit) == bit;
|
||||
|
||||
pieces.push(isCompleted);
|
||||
pieceIndex++;
|
||||
pieces[pieceIndex++] = isCompleted;
|
||||
|
||||
if (pieceIndex >= pieceCount) {
|
||||
return pieces;
|
||||
|
@ -483,7 +486,7 @@
|
|||
return getCombinedPieces(bitField, pieceCount);
|
||||
},
|
||||
estimateHealthPercentFromPeers: function (task, peers) {
|
||||
if (peers.length < 1) {
|
||||
if (!task || task.numPieces < 1 || peers.length < 1) {
|
||||
return task.completePercent;
|
||||
}
|
||||
|
||||
|
@ -519,6 +522,7 @@
|
|||
|
||||
var totalCompletedPieceCount = 0;
|
||||
|
||||
if (totalPieces.length > 0) {
|
||||
while (true) {
|
||||
var completed = true;
|
||||
|
||||
|
@ -535,6 +539,7 @@
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (totalCompletedPieceCount <= maxCompletedPieceCount) {
|
||||
return maxCompletedPercent;
|
||||
|
|
Reference in a new issue