Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Please codacy (operator precedence).
[simgrid.git] / examples / msg / app-bittorrent / messages.c
index a0cfe07..c353692 100644 (file)
@@ -7,10 +7,9 @@
 #include "messages.h"
 #include "bittorrent.h"
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_messages,
-                             "Messages specific for the message factory");
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_messages, "Messages specific for the message factory");
 
-#define BITS_TO_BYTES(x) ((x / 8) + (x % 8) ? 1 : 0)
+#define BITS_TO_BYTES(x) (((x) / 8 + (x) % 8) ? 1 : 0)
 
 /** @brief Build a new empty message
  * @param type type of the message
@@ -42,8 +41,8 @@ msg_task_t task_message_index_new(e_message_type type, const char *issuer_host_n
   return task;
 }
 
-msg_task_t task_message_bitfield_new(const char *issuer_host_name, const char *mailbox, int peer_id, char *bitfield,
-                                     int bitfield_size)
+msg_task_t task_message_bitfield_new(const char *issuer_host_name, const char *mailbox, int peer_id,
+                                     unsigned int bitfield, int bitfield_size)
 {
   msg_task_t task = task_message_new(MESSAGE_BITFIELD, issuer_host_name, mailbox, peer_id,
                                      task_message_size(MESSAGE_BITFIELD) + BITS_TO_BYTES(bitfield_size));
@@ -94,8 +93,6 @@ int task_message_size(e_message_type type)
     size = MESSAGE_UNCHOKE_SIZE;
     break;
   case MESSAGE_INTERESTED:
-    size = MESSAGE_INTERESTED_SIZE;
-    break;
   case MESSAGE_NOTINTERESTED:
     size = MESSAGE_INTERESTED_SIZE;
     break;
@@ -114,6 +111,8 @@ int task_message_size(e_message_type type)
   case MESSAGE_CANCEL:
     size = MESSAGE_CANCEL_SIZE;
     break;
+  default:
+    THROW_IMPOSSIBLE;
   }
   return size;
 }