Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change some sprintf into snprintf
[simgrid.git] / examples / msg / async-waitany / async-waitany.c
index 4e053e4..f5d7631 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2010-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2010-2016. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -8,11 +7,6 @@
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_waitany, "Messages specific for this msg example");
 
-/** @addtogroup MSG_examples
- *
- * - <b>Wait any: async-waitany/async-waitany.c</b>. Illustrates the use of the @ref MSG_comm_waitany function.
- */
-
 static int sender(int argc, char *argv[])
 {
   long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
@@ -25,7 +19,7 @@ static int sender(int argc, char *argv[])
   int i;
   msg_task_t task;
   char mailbox[256];
-  char sprintf_buffer[256];
+  char snprintf_buffer[256];
   msg_comm_t comm;
 
   for (i = 0; i < number_of_tasks; i++) {
@@ -34,12 +28,12 @@ static int sender(int argc, char *argv[])
     else
       coef = (i + 1);
 
-    sprintf(mailbox, "receiver-%ld", (i % receivers_count));
-    sprintf(sprintf_buffer, "Task_%d", i);
-    task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size / coef, NULL);
+    snprintf(mailbox,255, "receiver-%ld", (i % receivers_count));
+    snprintf(snprintf_buffer,255, "Task_%d", i);
+    task = MSG_task_create(snprintf_buffer, task_comp_size, task_comm_size / coef, NULL);
     comm = MSG_task_isend(task, mailbox);
     xbt_dynar_push_as(d, msg_comm_t, comm);
-    XBT_INFO("Send to receiver-%ld %s comm_size %f", i % receivers_count, sprintf_buffer, task_comm_size / coef);
+    XBT_INFO("Send to receiver-%ld %s comm_size %f", i % receivers_count, snprintf_buffer, task_comm_size / coef);
   }
   /* Here we are waiting for the completion of all communications */
 
@@ -50,13 +44,11 @@ static int sender(int argc, char *argv[])
   xbt_dynar_free(&d);
 
   /* Here we are waiting for the completion of all tasks */
-  sprintf(mailbox, "finalize");
-
   msg_comm_t res_irecv;
   XBT_ATTRIB_UNUSED msg_error_t res_wait;
   for (i = 0; i < receivers_count; i++) {
     task = NULL;
-    res_irecv = MSG_task_irecv(&(task), mailbox);
+    res_irecv = MSG_task_irecv(&(task), "finalize");
     res_wait = MSG_comm_wait(res_irecv, -1);
     xbt_assert(res_wait == MSG_OK, "MSG_comm_wait failed");
     MSG_comm_destroy(res_irecv);
@@ -78,7 +70,7 @@ static int receiver(int argc, char *argv[])
   XBT_ATTRIB_UNUSED int read;
   read = sscanf(argv[1], "%d", &id);
   xbt_assert(read, "Invalid argument %s\n", argv[1]);
-  sprintf(mailbox, "receiver-%d", id);
+  snprintf(mailbox,79, "receiver-%d", id);
   MSG_process_sleep(10);
   msg_comm_t res_irecv;
   for (int i = 0; i < tasks; i++) {
@@ -105,8 +97,7 @@ static int receiver(int argc, char *argv[])
   xbt_free(task);
 
   /* Here we tell to sender that all tasks are done */
-  sprintf(mailbox, "finalize");
-  res_irecv = MSG_task_isend(MSG_task_create(NULL, 0, 0, NULL), mailbox);
+  res_irecv = MSG_task_isend(MSG_task_create(NULL, 0, 0, NULL), "finalize");
   MSG_comm_wait(res_irecv, -1);
   MSG_comm_destroy(res_irecv);
   XBT_INFO("I'm done. See you!");