char full_name[1024];
msg_file_t file = NULL;
- sprintf(full_name, "%s:%s", MSG_process_get_name(MSG_process_self()), file_name);
+ snprintf(full_name,1023, "%s:%s", MSG_process_get_name(MSG_process_self()), file_name);
file = (msg_file_t) xbt_dict_get_or_null(opened_files, full_name);
return file;
msg_file_t file = NULL;
double clock = MSG_get_clock();
- sprintf(full_name, "%s:%s", MSG_process_get_name(MSG_process_self()), file_name);
+ snprintf(full_name,1023, "%s:%s", MSG_process_get_name(MSG_process_self()), file_name);
ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name);
file = MSG_file_open(file_name, NULL);
void peer_init(peer_t peer, int id, int seed)
{
peer->id = id;
- sprintf(peer->mailbox, "%d", id);
- sprintf(peer->mailbox_tracker, "tracker_%d", id);
+ snprintf(peer->mailbox,MAILBOX_SIZE-1, "%d", id);
+ snprintf(peer->mailbox_tracker,MAILBOX_SIZE-1, "tracker_%d", id);
peer->peers = xbt_dict_new();
peer->active_peers = xbt_dict_new();
peer->hostname = MSG_host_get_name(MSG_host_self());
char mailbox[256];
char task_name[256];
- sprintf(mailbox, "worker-%ld", i % workers_count); /* - Select a @ref worker in a round-robin way */
- sprintf(task_name, "Task_%d", i);
+ snprintf(mailbox,255, "worker-%ld", i % workers_count); /* - Select a @ref worker in a round-robin way */
+ snprintf(task_name,255, "Task_%d", i);
msg_task_t task = MSG_task_create(task_name, comp_size, comm_size, NULL); /* - Create a task */
if (number_of_tasks < 10000 || i % 10000 == 0)
XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, number_of_tasks, mailbox);
for (i = 0; i < workers_count; i++) { /* - Eventually tell all the workers to stop by sending a "finalize" task */
char mailbox[80];
- sprintf(mailbox, "worker-%ld", i % workers_count);
+ snprintf(mailbox,79, "worker-%ld", i % workers_count);
msg_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
MSG_task_send(finalize, mailbox);
}
long id= xbt_str_parse_int(argv[1], "Invalid argument %s");
- sprintf(mailbox, "worker-%ld", id);
+ snprintf(mailbox,79, "worker-%ld", id);
while (1) { /* The worker wait in an infinite loop for tasks sent by the \ref master */
int res = MSG_task_receive(&(task), mailbox);
msg_task_t task = NULL;
XBT_ATTRIB_UNUSED int res;
if (rank == 0){ /* - The root (rank 0) first sends the token then waits to receive it back */
- sprintf(mailbox, "%d", rank+1);
+ snprintf(mailbox,255, "%d", rank+1);
task = MSG_task_create("Token", 0, task_comm_size, NULL);
XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"", rank, task->name,mailbox);
MSG_task_send(task, mailbox);
XBT_INFO("Host \"%d\" received \"%s\"",rank, MSG_task_get_name(task));
if(rank+1 == MSG_get_host_number()) /* - Except for the last one which sends the token back to rank 0 */
- sprintf(mailbox, "0");
+ snprintf(mailbox,255, "0");
else
- sprintf(mailbox, "%d", rank+1);
+ snprintf(mailbox,255, "%d", rank+1);
XBT_INFO("Host \"%d\" send '%s' to Host \"%s\"",rank,task->name,mailbox);
MSG_task_send(task, mailbox);
}
MSG_process_sleep(sleep_start_time);
for (i = 0; i < number_of_tasks; i++) {
char mailbox[256];
- char sprintf_buffer[256];
+ char snprintf_buffer[256];
- sprintf(mailbox, "receiver-%ld", i % receivers_count);
- sprintf(sprintf_buffer, "Task_%d", i);
+ snprintf(mailbox,255, "receiver-%ld", i % receivers_count);
+ snprintf(snprintf_buffer,255, "Task_%d", i);
/* This process first creates a task and send it asynchronously with @ref MSG_task_isend. Then, if: */
- task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
+ task = MSG_task_create(snprintf_buffer, task_comp_size, task_comm_size, NULL);
comm = MSG_task_isend(task, mailbox);
XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);
for (i = 0; i < receivers_count; i++) {
char mailbox[80];
- sprintf(mailbox, "receiver-%ld", i % receivers_count);
+ snprintf(mailbox,79, "receiver-%ld", i % receivers_count);
task = MSG_task_create("finalize", 0, 0, 0);
comm = MSG_task_isend(task, mailbox);
XBT_INFO("Send to receiver-%ld finalize", i % receivers_count);
MSG_process_sleep(sleep_start_time); /* This process first sleeps for "start time" seconds. */
- sprintf(mailbox, "receiver-%d", id);
+ snprintf(mailbox,79, "receiver-%d", id);
while (1) {
res_irecv = MSG_task_irecv(&(task), mailbox); /* Then it posts asynchronous receives (@ref MSG_task_irecv) and*/
XBT_INFO("Wait to receive a task");
msg_task_t task = NULL;
for (i = 0; i < number_of_tasks; i++) {
char mailbox[256];
- char sprintf_buffer[256];
- 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, NULL);
+ char snprintf_buffer[256];
+ 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, NULL);
comm[i] = MSG_task_isend(task, mailbox);
XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);
}
for (i = 0; i < receivers_count; i++) {
char mailbox[80];
- sprintf(mailbox, "receiver-%ld", i % receivers_count);
+ snprintf(mailbox,79, "receiver-%ld", i % receivers_count);
task = MSG_task_create("finalize", 0, 0, 0);
comm[i + number_of_tasks] = MSG_task_isend(task, mailbox);
XBT_INFO("Send to receiver-%ld finalize", i % receivers_count);
read = sscanf(argv[1], "%d", &id);
xbt_assert(read, "Invalid argument %s\n", argv[1]);
MSG_process_sleep(10);
- sprintf(mailbox, "receiver-%d", id);
+ snprintf(mailbox,79, "receiver-%d", id);
while (1) {
res_irecv = MSG_task_irecv(&(task), mailbox);
XBT_INFO("Wait to receive a task");
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++) {
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 */
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++) {
d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
/* 1. Populate the dynar */
for (cpt = 0; cpt < NB_ELEM; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
s1 = xbt_strdup(buf);
xbt_dynar_push(d, &s1);
}
for (cpt = 0; cpt < NB_ELEM; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
s1 = xbt_strdup(buf);
xbt_dynar_replace(d, cpt, &s1);
}
for (cpt = 0; cpt < NB_ELEM; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
s1 = xbt_strdup(buf);
xbt_dynar_replace(d, cpt, &s1);
}
for (cpt = 0; cpt < NB_ELEM; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
s1 = xbt_strdup(buf);
xbt_dynar_replace(d, cpt, &s1);
}
for (cpt = 0; cpt < NB_ELEM; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
xbt_dynar_shift(d, &s2);
xbt_test_assert(!strcmp(buf, s2), "The retrieved value is not the same than the injected one (%s!=%s)", buf, s2);
free(s2);
xbt_test_add("==== Unshift, traverse and pop %d strings", NB_ELEM);
d = xbt_dynar_new(sizeof(char **), &xbt_free_ref);
for (cpt = 0; cpt < NB_ELEM; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
s1 = xbt_strdup(buf);
xbt_dynar_unshift(d, &s1);
}
/* 2. Traverse the dynar with the macro */
xbt_dynar_foreach(d, iter, s1) {
- sprintf(buf, "%u", NB_ELEM - iter - 1);
+ snprintf(buf,1023, "%u", NB_ELEM - iter - 1);
xbt_test_assert(!strcmp(buf, s1), "The retrieved value is not the same than the injected one (%s!=%s)", buf, s1);
}
/* 3. Traverse the dynar with the macro */
for (cpt = 0; cpt < NB_ELEM; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
xbt_dynar_pop(d, &s2);
xbt_test_assert(!strcmp(buf, s2), "The retrieved value is not the same than the injected one (%s!=%s)", buf, s2);
free(s2);
xbt_test_add("==== Push %d strings, insert %d strings in the middle, shift everything", NB_ELEM, NB_ELEM / 5);
d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
for (cpt = 0; cpt < NB_ELEM; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
s1 = xbt_strdup(buf);
xbt_dynar_push(d, &s1);
}
for (cpt = 0; cpt < NB_ELEM / 5; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
s1 = xbt_strdup(buf);
xbt_dynar_insert_at(d, NB_ELEM / 2, &s1);
}
for (cpt = 0; cpt < NB_ELEM / 2; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
xbt_dynar_shift(d, &s2);
xbt_test_assert(!strcmp(buf, s2),
"The retrieved value is not the same than the injected one at the begining (%s!=%s)", buf, s2);
free(s2);
}
for (cpt = (NB_ELEM / 5) - 1; cpt >= 0; cpt--) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
xbt_dynar_shift(d, &s2);
xbt_test_assert(!strcmp(buf, s2),
"The retrieved value is not the same than the injected one in the middle (%s!=%s)", buf, s2);
free(s2);
}
for (cpt = NB_ELEM / 2; cpt < NB_ELEM; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
xbt_dynar_shift(d, &s2);
xbt_test_assert(!strcmp(buf, s2), "The retrieved value is not the same than the injected one at the end (%s!=%s)",
buf, s2);
xbt_test_add("==== Push %d strings, remove %d-%d. free the rest", NB_ELEM, 2 * (NB_ELEM / 5), 4 * (NB_ELEM / 5));
d = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
for (cpt = 0; cpt < NB_ELEM; cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
s1 = xbt_strdup(buf);
xbt_dynar_push(d, &s1);
}
for (cpt = 2 * (NB_ELEM / 5); cpt < 4 * (NB_ELEM / 5); cpt++) {
- sprintf(buf, "%d", cpt);
+ snprintf(buf,1023, "%d", cpt);
xbt_dynar_remove_at(d, 2 * (NB_ELEM / 5), &s2);
xbt_test_assert(!strcmp(buf, s2), "Remove a bad value. Got %s, expected %s", s2, buf);
free(s2);