Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace sprintf by snprintf.
[simgrid.git] / src / xbt / dict.c
index 59927b7..8c98500 100644 (file)
@@ -44,6 +44,9 @@ xbt_dict_t xbt_dict_new(void)
  */
 xbt_dict_t xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn)
 {
+  if (dict_elm_mallocator == NULL)
+    xbt_dict_preinit();
+
   xbt_dict_t dict;
 
   dict = xbt_new(s_xbt_dict_t, 1);
@@ -527,10 +530,14 @@ void xbt_dict_dump_sizes(xbt_dict_t dict)
  */
 void xbt_dict_preinit(void)
 {
-  dict_elm_mallocator = xbt_mallocator_new(256, dict_elm_mallocator_new_f, dict_elm_mallocator_free_f,
-                                           dict_elm_mallocator_reset_f);
-  dict_het_elm_mallocator = xbt_mallocator_new(256, dict_het_elm_mallocator_new_f, dict_het_elm_mallocator_free_f,
-                                               dict_het_elm_mallocator_reset_f);
+  if (dict_elm_mallocator == NULL)
+    dict_elm_mallocator = xbt_mallocator_new(
+      256, dict_elm_mallocator_new_f, dict_elm_mallocator_free_f,
+      dict_elm_mallocator_reset_f);
+  if (dict_het_elm_mallocator == NULL)
+    dict_het_elm_mallocator = xbt_mallocator_new(
+      256, dict_het_elm_mallocator_new_f, dict_het_elm_mallocator_free_f,
+      dict_het_elm_mallocator_reset_f);
 }
 
 /**
@@ -975,7 +982,7 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test")
     /* 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); */
@@ -990,7 +997,7 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test")
     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));
@@ -1003,7 +1010,7 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test")
   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);