From: Frederic Suter Date: Thu, 16 Feb 2017 08:14:14 +0000 (+0100) Subject: fix newly introduced bugs X-Git-Tag: v3_15~353 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/98c6a77b4cfe9cc585b3f2d00f9b4b0647c3ffa2 fix newly introduced bugs --- diff --git a/examples/msg/app-bittorrent/connection.c b/examples/msg/app-bittorrent/connection.c index 5548625048..43140e6fb8 100644 --- a/examples/msg/app-bittorrent/connection.c +++ b/examples/msg/app-bittorrent/connection.c @@ -40,5 +40,5 @@ void connection_free(void *data) } int connection_has_piece(connection_t connection, unsigned int piece){ - return !!(connection->bitfield & 1<bitfield & 1U<>= 1 ; + unsigned int n = bitfield; + while (n){ + count += n & 1U; + n >>= 1U ; } return count; } int peer_has_not_piece(peer_t peer, unsigned int piece){ - return !(peer->bitfield & 1<bitfield & 1U<current_pieces & 1<current_pieces & 1U<active_peers = xbt_dict_new_homogeneous(NULL); if (seed) { - peer->bitfield = (1<bitfield_blocks = (1ULL<<(FILE_PIECES * PIECES_BLOCKS))-1; + peer->bitfield = (1U<bitfield_blocks = (1ULL<<(FILE_PIECES * PIECES_BLOCKS))-1ULL ; } else { peer->bitfield = 0; peer->bitfield_blocks = 0; @@ -267,7 +268,7 @@ void peer_free(peer_t peer) */ int has_finished(unsigned int bitfield) { - return bitfield == (1<index); xbt_assert((message->index >= 0 && message->index < FILE_PIECES), "Wrong HAVE message received"); - remote_peer->bitfield = remote_peer->bitfield | (1<index); + remote_peer->bitfield = remote_peer->bitfield | (1U<index); peer->pieces_count[message->index]++; //If the piece is in our pieces, we tell the peer that we are interested. if ((remote_peer->am_interested == 0) && peer_has_not_piece(peer,message->index)) { @@ -396,7 +397,7 @@ void handle_message(peer_t peer, msg_task_t task) //Removing the piece from our piece list remove_current_piece(peer, remote_peer, message->index); //Setting the fact that we have the piece - peer->bitfield = peer->bitfield | (1<index); + peer->bitfield = peer->bitfield | (1U<index); char* status = xbt_malloc0(FILE_PIECES+1); get_status(&status, peer->bitfield); XBT_DEBUG("My status is now %s", status); @@ -433,15 +434,15 @@ void request_new_piece_to_peer(peer_t peer, connection_t remote_peer) { int piece = select_piece_to_download(peer, remote_peer); if (piece != -1) { - peer->current_pieces|= (1 << (unsigned int) piece); + peer->current_pieces|= (1U << (unsigned int) piece); send_request_to_peer(peer, remote_peer, piece); } } /** remove current_piece from the list of currently downloaded pieces. */ -void remove_current_piece(peer_t peer, connection_t remote_peer, int current_piece) +void remove_current_piece(peer_t peer, connection_t remote_peer, unsigned int current_piece) { - peer->current_pieces &= ~(1 << (unsigned int) current_piece); + peer->current_pieces &= ~(1U << current_piece); remote_peer->current_piece = -1; } @@ -694,7 +695,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 |= (1ULL<<(index * PIECES_BLOCKS + i)); + peer->bitfield_blocks |= (1ULL<<(unsigned int)(index * PIECES_BLOCKS + i)); } } @@ -723,7 +724,7 @@ int get_first_block(peer_t peer, int piece) /** Indicates if the remote peer has a piece not stored by the local peer */ int is_interested(peer_t peer, connection_t remote_peer) { - return !!(remote_peer->bitfield & (peer->bitfield^((1<bitfield & (peer->bitfield^((1<