From a9c7137c5855dfaf080dc89e5d2a3367019d0a5a Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 15 Feb 2017 21:34:23 +0100 Subject: [PATCH] used unsigned long long to have more than 50 bits --- examples/msg/app-bittorrent/peer.c | 8 ++++---- examples/msg/app-bittorrent/peer.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/msg/app-bittorrent/peer.c b/examples/msg/app-bittorrent/peer.c index 3af98ed4c0..7921e8ad35 100644 --- a/examples/msg/app-bittorrent/peer.c +++ b/examples/msg/app-bittorrent/peer.c @@ -229,7 +229,7 @@ peer_t peer_init(int id, int seed) if (seed) { peer->bitfield = (1<bitfield_blocks = (1L<<(FILE_PIECES * PIECES_BLOCKS))-1; + peer->bitfield_blocks = (1ULL<<(FILE_PIECES * PIECES_BLOCKS))-1; } else { peer->bitfield = 0; peer->bitfield_blocks = 0; @@ -694,7 +694,7 @@ void update_bitfield_blocks(peer_t peer, int index, int block_index, int block_l xbt_assert((index >= 0 && index <= FILE_PIECES), "Wrong piece."); xbt_assert((block_index >= 0 && block_index <= PIECES_BLOCKS), "Wrong block : %d.", block_index); for (int i = block_index; i < (block_index + block_length); i++) { - peer->bitfield_blocks |= (1L<<(index * PIECES_BLOCKS + i)); + peer->bitfield_blocks |= (1ULL<<(index * PIECES_BLOCKS + i)); } } @@ -702,7 +702,7 @@ void update_bitfield_blocks(peer_t peer, int index, int block_index, int block_l int piece_complete(peer_t peer, int index) { for (int i = 0; i < PIECES_BLOCKS; i++) { - if (!(peer->bitfield_blocks & 1L<<(index * PIECES_BLOCKS + i))) { + if (!(peer->bitfield_blocks & 1ULL<<(index * PIECES_BLOCKS + i))) { return 0; } } @@ -713,7 +713,7 @@ int piece_complete(peer_t peer, int index) int get_first_block(peer_t peer, int piece) { for (int i = 0; i < PIECES_BLOCKS; i++) { - if (!(peer->bitfield_blocks & 1L<<(piece * PIECES_BLOCKS + i))) { + if (!(peer->bitfield_blocks & 1ULL<<(piece * PIECES_BLOCKS + i))) { return i; } } diff --git a/examples/msg/app-bittorrent/peer.h b/examples/msg/app-bittorrent/peer.h index cca374b9aa..4c28fc37a1 100644 --- a/examples/msg/app-bittorrent/peer.h +++ b/examples/msg/app-bittorrent/peer.h @@ -18,7 +18,7 @@ typedef struct s_peer { int id; //peer id unsigned int bitfield; //list of pieces the peer has. - unsigned long bitfield_blocks; //list of blocks the peer has. + unsigned long long bitfield_blocks; //list of blocks the peer has. short *pieces_count; //number of peers that have each piece. unsigned int current_pieces; //current pieces the peer is downloading -- 2.20.1