/* Latency */
time = MSG_get_clock();
- sprintf(sprintf_buffer_la, "latency task");
+ snprintf(sprintf_buffer_la,64, "latency task");
task_la = MSG_task_create(sprintf_buffer_la, 0.0, task_comm_size_lat, NULL);
task_la->data = xbt_new(double, 1);
*(double *) task_la->data = time;
/* Bandwidth */
time = MSG_get_clock();
- sprintf(sprintf_buffer_bw, "bandwidth task");
+ snprintf(sprintf_buffer_bw,64, "bandwidth task");
task_bw = MSG_task_create(sprintf_buffer_bw, 0.0, task_comm_size_bw, NULL);
task_bw->data = xbt_new(double, 1);
*(double *) task_bw->data = time;
/* worker name */
char *workername = argv[2];
int id = xbt_str_parse_int(argv[3], "Invalid ID as argument 3: %s"); //unique id to control statistics
- char *id_alias = bprintf("flow_%d", id);
+ char *id_alias = xbt_malloc(20*sizeof(char));
+ snprintf(id_alias, 20, "flow_%d", id);
workernames[id] = workername;
TRACE_category(id_alias);
timer_start = 1 ;
/* time measurement */
- sprintf(id_alias, "%d", id);
+ snprintf(id_alias,20,"%d", id);
start_time = MSG_get_clock();
MSG_task_send(todo, id_alias);
end_time = MSG_get_clock();
XBT_DEBUG ("Worker started");
int id = xbt_str_parse_int(argv[1], "Invalid id: %s");
- sprintf(id_alias, "%d", id);
+ snprintf(id_alias,10, "%d", id);
msg_error_t a = MSG_task_receive(&(task), id_alias);
unsigned int i=0,j=0;
char nm[BLOCK_SIZE];
- snprintf(nm,BLOCK_SIZE -1,"DT_SH.%c",cls);
+ snprintf(nm,BLOCK_SIZE,"DT_SH.%c",cls);
dg=newDGraph(nm);
while(tmpS>1){
tmpS>>=1;
}
for(i=0;i<numSources;i++){
- snprintf(nm,BLOCK_SIZE -1,"Source.%d",i);
+ snprintf(nm,BLOCK_SIZE,"Source.%d",i);
nd=newNode(nm);
AttachNode(dg,nd);
}
for(j=0;j<numOfLayers;j++){
mask=0x00000001<<j;
for(i=0;i<numSources;i++){
- snprintf(nm,BLOCK_SIZE -1,"Comparator.%d",(i+j*firstLayerNode));
+ snprintf(nm,BLOCK_SIZE,"Comparator.%d",(i+j*firstLayerNode));
nd=newNode(nm);
AttachNode(dg,nd);
ndoff=i&(~mask);
}
mask=0x00000001<<numOfLayers;
for(i=0;i<numSources;i++){
- snprintf(nm,BLOCK_SIZE -1,"Sink.%d",i);
+ snprintf(nm,BLOCK_SIZE,"Sink.%d",i);
nd=newNode(nm);
AttachNode(dg,nd);
ndoff=i&(~mask);
DGArc *ar=NULL;
char nm[BLOCK_SIZE];
- sprintf(nm,"DT_WH.%c",cls);
+ snprintf(nm,BLOCK_SIZE,"DT_WH.%c",cls);
dg=newDGraph(nm);
for(i=0;i<numSources;i++){
- sprintf(nm,"Sink.%d",i);
+ snprintf(nm,BLOCK_SIZE,"Sink.%d",i);
nd=newNode(nm);
AttachNode(dg,nd);
}
numLayerNodes=numLayerNodes/maxInDeg;
if(numLayerNodes*maxInDeg<numPrevLayerNodes)numLayerNodes++;
for(i=0;i<numLayerNodes;i++){
- sprintf(nm,"Comparator.%d",totComparators);
+ snprintf(nm,BLOCK_SIZE,"Comparator.%d",totComparators);
totComparators++;
nd=newNode(nm);
id=AttachNode(dg,nd);
int id=0, sid=0;
char nm[BLOCK_SIZE];
- sprintf(nm,"DT_BH.%c",cls);
+ snprintf(nm,BLOCK_SIZE,"DT_BH.%c",cls);
dg=newDGraph(nm);
for(i=0;i<numSources;i++){
- sprintf(nm,"Source.%d",i);
+ snprintf(nm,BLOCK_SIZE,"Source.%d",i);
nd=newNode(nm);
AttachNode(dg,nd);
}
numLayerNodes=numLayerNodes/maxInDeg;
if(numLayerNodes*maxInDeg<numPrevLayerNodes)numLayerNodes++;
for(i=0;i<numLayerNodes;i++){
- sprintf(nm,"Comparator.%d",totComparators);
+ snprintf(nm,BLOCK_SIZE,"Comparator.%d",totComparators);
totComparators++;
nd=newNode(nm);
id=AttachNode(dg,nd);
* string (for printing). Have to strip off the decimal point put in there by the floating point print statement
* (internal file) */
fprintf(stdout," NAS Parallel Benchmarks 3.2 -- EP Benchmark");
- sprintf(size,"%lu",(unsigned long)pow(2,m+1));
+ snprintf(size,500,"%lu",(unsigned long)pow(2,m+1));
//size = size.replace('.', ' ');
fprintf(stdout," Number of random numbers generated: %s\n",size);
fprintf(stdout," Number of active processes: %d\n",no_nodes);
char sprintf_buffer[256];
msg_task_t task = NULL;
- sprintf(mailbox, "slave-%ld", i % slaves_count);
- sprintf(sprintf_buffer, "Task_%d", i);
+ snprintf(mailbox,256, "slave-%ld", i % slaves_count);
+ snprintf(sprintf_buffer,256, "Task_%d", i);
task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
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 < slaves_count; i++) {
char mailbox[80];
- sprintf(mailbox, "slave-%ld", i % slaves_count);
+ snprintf(mailbox,80, "slave-%ld", i % slaves_count);
msg_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
MSG_task_send(finalize, mailbox);
}
{
MPI_Init(&argc, &argv);
- int rank, size;
+ int rank;
+ int size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
XBT_INFO("alltoall for rank %d", rank);
read = sscanf(argv[1], "%d", &id);
xbt_assert(read, "Invalid argument %s\n", argv[1]);
- sprintf(mailbox, "slave-%d", id);
+ snprintf(mailbox,80, "slave-%d", id);
while (1) {
res = MSG_task_receive(&(task), mailbox);
xbt_assert(res == MSG_OK, "MSG_task_get failed");
-// XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
- if (!strcmp(MSG_task_get_name(task), "finalize")) {
+ if (strcmp(MSG_task_get_name(task), "finalize")==0) {
MSG_task_destroy(task);
break;
}
-// XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
MSG_task_execute(task);
-// XBT_INFO("\"%s\" done", MSG_task_get_name(task));
MSG_task_destroy(task);
task = NULL;
}
switch (lua_type(L, index)) {
case LUA_TNIL:
- sprintf(buff, "nil");
+ snprintf(buff, 4, "nil");
break;
case LUA_TNUMBER:
- sprintf(buff, "%.3f", lua_tonumber(L, index));
+ snprintf(buff, 64, "%.3f", lua_tonumber(L, index));
break;
case LUA_TBOOLEAN:
- sprintf(buff, "%s", lua_toboolean(L, index) ? "true" : "false");
+ snprintf(buff, 64, "%s", lua_toboolean(L, index) ? "true" : "false");
break;
case LUA_TSTRING:
case LUA_TFUNCTION:
if (lua_iscfunction(L, index)) {
- sprintf(buff, "C-function");
+ snprintf(buff, 11, "C-function");
}
else {
- sprintf(buff, "function");
+ snprintf(buff, 9, "function");
}
break;
case LUA_TTABLE:
- sprintf(buff, "table(%p)", lua_topointer(L, index));
+ snprintf(buff, 64, "table(%p)", lua_topointer(L, index));
break;
case LUA_TLIGHTUSERDATA:
case LUA_TUSERDATA:
- sprintf(buff, "userdata(%p)", lua_touserdata(L, index));
+ snprintf(buff, 64, "userdata(%p)", lua_touserdata(L, index));
break;
case LUA_TTHREAD:
- sprintf(buff, "thread");
+ snprintf(buff, 7, "thread");
break;
}
return buff;
p[0] = '\0';
for (int i = 1; i <= top; i++) { /* repeat for each level */
- p += sprintf(p, "%s ", sglua_tostring(L, i));
+ p += snprintf(p, 2048-(p-buff), "%s ", sglua_tostring(L, i));
}
XBT_DEBUG("%s%s", msg, buff);
xbt_dynar_foreach(hier_list, iter, number) {
if( iter != length-1 ) {
- sprintf(buf, "%d.", number);
+ snprintf(buf, 1024, "%d.", number);
} else {
- sprintf(buf, "%d", number);
+ snprintf(buf, 1024, "%d", number);
}
- strcat(outbuf, buf);
+ sntrcat(outbuf, buf, strlen(buf));
}
xbt_dynar_free(&hier_list);
int chars_left, used;
va_list ap; va_start(ap, fmt);
#ifdef FLEXML_yylineno
- used = sprintf(flexml_err_msg,
+ used = snprintf(flexml_err_msg,flexml_max_err_msg_size,
"Invalid XML (XML input line %d, state %d): ",
dax_lineno, YY_START);
#else
- used = sprintf(flexml_err_msg,
+ used = snprintf(flexml_err_msg,flexml_max_err_msg_size,
"Invalid XML (state %d): ",
YY_START);
#endif
dst = (SD_task_t)xbt_dict_get_or_null(jobs, dst_name);
if (size > 0) {
- char *name = (char*)xbt_malloc((strlen(src_name)+strlen(dst_name)+6)*sizeof(char));
- sprintf(name, "%s->%s", src_name, dst_name);
+ int namesize=(strlen(src_name)+strlen(dst_name)+6);
+ char *name = (char*)xbt_malloc(namesize*sizeof(char*));
+ snprintf(name,namesize, "%s->%s", src_name, dst_name);
XBT_DEBUG("See <transfer id=%s amount = %.0f>", name, size);
if (!(task = (SD_task_t)xbt_dict_get_or_null(jobs, name))) {
if (seq_or_par == sequential)
const char *description)
{
char *p = result +
- sprintf(result, "%s. Possible values: %s", description,
+ snprintf(result,1024-strlen(result), "%s. Possible values: %s", description,
model_description[0].name ? model_description[0].name : "n/a");
for (int i = 1; model_description[i].name; i++)
- p += sprintf(p, ", %s", model_description[i].name);
- sprintf(p, ".\n (use 'help' as a value to see the long description of each %s)", name);
+ p += snprintf(p,1024, ", %s", model_description[i].name);
+ snprintf(p,1024, ".\n (use 'help' as a value to see the long description of each %s)", name);
}
/* create the config set, register what should be and parse the command line*/
type=PJ_type_event_new(#cat, PJ_type_get_root());\
}\
char cont_name[25];\
- sprintf(cont_name, "rank-%d", smpi_process_index());\
+ snprintf(cont_name,25, "rank-%d", smpi_process_index());\
val_t value = PJ_value_get_or_new(mpi_coll_##cat##_description[i].name,"1.0 1.0 1.0", type);\
new_pajeNewEvent (SIMIX_get_clock(), PJ_container_get(cont_name), type, value);\
}
/* Printing Objective */
var_list = &(sys->variable_set);
- sprintf(print_buf, "MAX-MIN ( ");
+ snprintf(print_buf,11, "MAX-MIN ( ");
trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
- strcat(trace_buf, print_buf);
+ strncat(trace_buf, print_buf, strlen(print_buf));
xbt_swag_foreach(_var, var_list) {
var = (lmm_variable_t)_var;
- sprintf(print_buf, "'%d'(%f) ", var->id_int, var->weight);
+ snprintf(print_buf,1024, "'%d'(%f) ", var->id_int, var->weight);
trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
- strcat(trace_buf, print_buf);
+ strncat(trace_buf, print_buf, strlen(print_buf));
}
- sprintf(print_buf, ")");
+ snprintf(print_buf,2, ")");
trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
- strcat(trace_buf, print_buf);
+ strncat(trace_buf, print_buf, strlen(print_buf));
XBT_DEBUG("%20s", trace_buf);
trace_buf[0] = '\000';
sum = 0.0;
//Show the enabled variables
elem_list = &(cnst->enabled_element_set);
- sprintf(print_buf, "\t");
+ snprintf(print_buf,2, "\t");
trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
- strcat(trace_buf, print_buf);
- sprintf(print_buf, "%s(",(cnst->sharing_policy)?"":"max");
+ strncat(trace_buf, print_buf, strlen(print_buf));
+ snprintf(print_buf,1024, "%s(",(cnst->sharing_policy)?"":"max");
trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
- strcat(trace_buf, print_buf);
+ strncat(trace_buf, print_buf, strlen(print_buf));
xbt_swag_foreach(_elem, elem_list) {
elem = (lmm_element_t)_elem;
- sprintf(print_buf, "%f.'%d'(%f) %s ", elem->value,
+ snprintf(print_buf,1024, "%f.'%d'(%f) %s ", elem->value,
elem->variable->id_int, elem->variable->value,(cnst->sharing_policy)?"+":",");
trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
- strcat(trace_buf, print_buf);
+ strncat(trace_buf, print_buf, strlen(print_buf));
if(cnst->sharing_policy)
sum += elem->value * elem->variable->value;
else
elem_list = &(cnst->disabled_element_set);
xbt_swag_foreach(_elem, elem_list) {
elem = (lmm_element_t)_elem;
- sprintf(print_buf, "%f.'%d'(%f) %s ", elem->value,
+ snprintf(print_buf,1024, "%f.'%d'(%f) %s ", elem->value,
elem->variable->id_int, elem->variable->value,(cnst->sharing_policy)?"+":",");
trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
- strcat(trace_buf, print_buf);
+ strncat(trace_buf, print_buf, strlen(print_buf));
if(cnst->sharing_policy)
sum += elem->value * elem->variable->value;
else
sum = MAX(sum,elem->value * elem->variable->value);
}
- sprintf(print_buf, "0) <= %f ('%d')", cnst->bound, cnst->id_int);
+ snprintf(print_buf,1024, "0) <= %f ('%d')", cnst->bound, cnst->id_int);
trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
- strcat(trace_buf, print_buf);
+ strncat(trace_buf, print_buf, strlen(print_buf));
if (!cnst->sharing_policy) {
- sprintf(print_buf, " [MAX-Constraint]");
+ snprintf(print_buf,1024, " [MAX-Constraint]");
trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
- strcat(trace_buf, print_buf);
+ strncat(trace_buf, print_buf, strlen(print_buf));
}
XBT_DEBUG("%s", trace_buf);
trace_buf[0] = '\000';
static char key[24];
std::stringstream sstream;
sstream << localSocket ;
- sprintf(key,"%s",sstream.str().c_str());
+ snprintf(key,24,"%s",sstream.str().c_str());
return key;
}
int chars_left, used;
va_list ap; va_start(ap, fmt);
#ifdef FLEXML_yylineno
- used = sprintf(flexml_err_msg,
+ used = snprintf(flexml_err_msg,flexml_max_err_msg_size,
"Invalid XML (XML input line %d, state %d): ",
surf_parse_lineno, YY_START);
#else
- used = sprintf(flexml_err_msg,
+ used = snprintf(flexml_err_msg,flexml_max_err_msg_size,
"Invalid XML (state %d): ",
YY_START);
#endif
} else {
binary_name = xbt_strdup(xbt_binary_name);
}
- cmd = curr = xbt_new(char, strlen(ADDR2LINE) + 25 + strlen(binary_name) + 32 * e->used);
+ int strsize=strlen(ADDR2LINE) + 25 + strlen(binary_name) + 32 * e->used;
+ cmd = curr = xbt_new(char, strsize);
- curr += sprintf(curr, "%s -f -e %s ", ADDR2LINE, binary_name);
+ curr += snprintf(curr,strsize, "%s -f -e %s ", ADDR2LINE, binary_name);
free(binary_name);
addrs = xbt_new(char *, e->used);
XBT_DEBUG("Set up a new address: %d, '%s'(%p)", i, addrs[i], addrs[i]);
/* Add it to the command line args */
- curr += sprintf(curr, "%s ", addrs[i]);
+ curr += snprintf(curr,strsize, "%s ", addrs[i]);
}
addr_len = strlen(addrs[0]);
if (p[0] == '[') {
/* library path not displayed in the map file either... */
free(p);
- sprintf(line_func, "??");
+ snprintf(line_func,3, "??");
} else {
p2 = strrchr(p, '(');
if (p2)
suite_title[i++] = '\n';
suite_title[80] = '\0';
- sprintf(suite_title + 40 - (suite_len + 4) / 2, "[ %s ]", suite->title);
+ snprintf(suite_title + 40 - (suite_len + 4) / 2, 81-(40 - (suite_len + 4)/ 2), "[ %s ]", suite->title);
suite_title[40 + (suite_len + 5) / 2] = '=';
if (!suite->enabled)
snprintf(suite_title + 70, 11, " DISABLED ");
/* if (!(j%1000)) { printf("."); fflush(stdout); } */
key = xbt_malloc(10);
- sprintf(key, "%d", j);
+ snprintf(key,10, "%d", j);
xbt_dict_set(head, key, key, &free);
}
/*xbt_dict_dump(head,(void (*)(void*))&printf); */
void *data;
/* if (i%10) printf("."); else printf("%d",i/10); fflush(stdout); */
for (j = 0; j < NB_ELM; j++) {
- sprintf(key, "%d", j);
+ snprintf(key,10, "%d", j);
data = xbt_dict_get(head, key);
xbt_test_assert(!strcmp(key, (char *) data), "with get, key=%s != data=%s", key, (char *) data);
data = xbt_dict_get_ext(head, key, strlen(key));
key = xbt_malloc(10);
for (j = 0; j < NB_ELM; j++) {
/* if (!(j%10000)) printf("."); fflush(stdout); */
- sprintf(key, "%d", j);
+ snprintf(key,10, "%d", j);
xbt_dict_remove(head, key);
}
free(key);
if (mapto == MAP_FAILED) {
char buff[1024];
fprintf(stderr,"Internal error: mmap returned MAP_FAILED! error: %s\n",strerror(errno));
- sprintf(buff,"cat /proc/%d/maps",getpid());
+ snprintf(buff,1024,"cat /proc/%d/maps",getpid());
int status = system(buff);
if (status == -1 || !(WIFEXITED(status) && WEXITSTATUS(status) == 0))
fprintf(stderr, "Something went wrong when trying to %s\n", buff);
p = res;
xbt_dynar_foreach(dyn, cpt, cursor) {
if ((int) cpt < dyn_len - 1)
- p += sprintf(p, "%s%s", cursor, sep);
+ p += snprintf(p,len, "%s%s", cursor, sep);
else
- p += sprintf(p, "%s", cursor);
+ p += snprintf(p,len, "%s", cursor);
}
return res;
}
q = res = xbt_malloc(len);
for (i=0;strs[i];i++) {
if (i!=0) { // not first loop
- q += sprintf(q, "%s%s", sep, strs[i]);
+ q += snprintf(q,len, "%s%s", sep, strs[i]);
} else {
- q += sprintf(q,"%s",strs[i]);
+ q += snprintf(q,len, "%s",strs[i]);
}
}
return res;
{
char name[2048];
int id = MSG_process_self_PID();
- sprintf(name,"%s%i", FILENAME1, id);
+ snprintf(name,2048,"%s%i", FILENAME1, id);
msg_file_t file = MSG_file_open(name, NULL);
XBT_INFO("process %d is writing!", id);
MSG_file_write(file, 3000000);