Skip to content

Commit

Permalink
Fix bitfield message length calculation
Browse files Browse the repository at this point in the history
Inspired by a fix by Pavel Sher.

Signed-off-by: Maxime Petazzoni <[email protected]>
  • Loading branch information
Maxime Petazzoni committed Nov 1, 2012
1 parent 69ba1b6 commit d0f68d5
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ public static BitfieldMessage parse(ByteBuffer buffer,
}

public static BitfieldMessage craft(BitSet availablePieces) {
byte[] bitfield = new byte[availablePieces.length()/8 + 1];
byte[] bitfield = new byte[
(int) Math.ceil((double)availablePieces.length()/8)];
for (int i=availablePieces.nextSetBit(0); i >= 0;
i=availablePieces.nextSetBit(i+1)) {
bitfield[i/8] |= 1 << (7 -(i % 8));
Expand Down

0 comments on commit d0f68d5

Please sign in to comment.