Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add an assert to please scan-build.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 16 Jul 2020 20:18:01 +0000 (22:18 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 17 Jul 2020 22:05:01 +0000 (00:05 +0200)
Fix "Assigned value is garbage or undefined" in 2nd loop (around lines 43-44).

examples/c/comm-waitall/comm-waitall.c
examples/c/comm-waitany/comm-waitany.c

index d6aca01..e676bc9 100644 (file)
@@ -23,6 +23,7 @@ static void sender(int argc, char* argv[])
   long messages_count  = xbt_str_parse_int(argv[1], "Invalid message count: %s");
   long message_size    = xbt_str_parse_int(argv[2], "Invalid message size: %s");
   long receivers_count = xbt_str_parse_int(argv[3], "Invalid amount of receivers: %s");
+  xbt_assert(receivers_count > 0);
 
   /* Array in which we store all ongoing communications */
   sg_comm_t* pending_comms = xbt_malloc(sizeof(sg_comm_t) * (messages_count + receivers_count));
@@ -38,9 +39,9 @@ static void sender(int argc, char* argv[])
   }
 
   /* Start dispatching all messages to receivers, in a round robin fashion */
-  for (int i = 0; i < messages_count; i++) {
+  for (long i = 0; i < messages_count; i++) {
     char msg_content[80];
-    snprintf(msg_content, 79, "Message %d", i);
+    snprintf(msg_content, 79, "Message %ld", i);
     sg_mailbox_t mbox = mboxes[i % receivers_count];
     XBT_INFO("Send '%s' to '%s'", msg_content, sg_mailbox_get_name(mbox));
     /* Create a communication representing the ongoing communication, and store it in pending_comms */
@@ -48,8 +49,8 @@ static void sender(int argc, char* argv[])
   }
 
   /* Start sending messages to let the workers know that they should stop */
-  for (int i = 0; i < receivers_count; i++) {
-    XBT_INFO("Send 'finalize' to 'receiver-%d'", i);
+  for (long i = 0; i < receivers_count; i++) {
+    XBT_INFO("Send 'finalize' to 'receiver-%ld'", i);
     char* end_msg                        = xbt_strdup("finalize");
     sg_mailbox_t mbox                    = mboxes[i % receivers_count];
     pending_comms[pending_comms_count++] = sg_mailbox_put_async(mbox, end_msg, 0);
index cd99dd3..9dd47e8 100644 (file)
@@ -22,6 +22,7 @@ static void sender(int argc, char* argv[])
   long messages_count  = xbt_str_parse_int(argv[1], "Invalid message count: %s");
   long msg_size        = xbt_str_parse_int(argv[2], "Invalid message size: %s");
   long receivers_count = xbt_str_parse_int(argv[3], "Invalid amount of receivers: %s");
+  xbt_assert(receivers_count > 0);
 
   /* Array in which we store all ongoing communications */
   sg_comm_t* pending_comms = xbt_malloc(sizeof(sg_comm_t) * (messages_count + receivers_count));
@@ -37,9 +38,9 @@ static void sender(int argc, char* argv[])
   }
 
   /* Start dispatching all messages to receivers, in a round robin fashion */
-  for (int i = 0; i < messages_count; i++) {
+  for (long i = 0; i < messages_count; i++) {
     char msg_content[80];
-    snprintf(msg_content, 79, "Message %d", i);
+    snprintf(msg_content, 79, "Message %ld", i);
     sg_mailbox_t mbox = mboxes[i % receivers_count];
     XBT_INFO("Send '%s' to '%s'", msg_content, sg_mailbox_get_name(mbox));
 
@@ -47,8 +48,8 @@ static void sender(int argc, char* argv[])
     pending_comms[pending_comms_count++] = sg_mailbox_put_async(mbox, xbt_strdup(msg_content), msg_size);
   }
   /* Start sending messages to let the workers know that they should stop */
-  for (int i = 0; i < receivers_count; i++) {
-    XBT_INFO("Send 'finalize' to 'receiver-%d'", i);
+  for (long i = 0; i < receivers_count; i++) {
+    XBT_INFO("Send 'finalize' to 'receiver-%ld'", i);
     char* end_msg                        = xbt_strdup("finalize");
     sg_mailbox_t mbox                    = mboxes[i % receivers_count];
     pending_comms[pending_comms_count++] = sg_mailbox_put_async(mbox, end_msg, 0);