Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'coverity_scan' of github.com:mquinson/simgrid
[simgrid.git] / examples / simdag / dax / dax_test.c
index de65c4c..3d68e1b 100644 (file)
@@ -18,11 +18,10 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test,
 
 static int name_compare_hosts(const void *n1, const void *n2)
 {
-  char name1[80], name2[80];
-  strcpy(name1, sg_host_get_name(*((sg_host_t *) n1)));
-  strcpy(name2, sg_host_get_name(*((sg_host_t *) n2)));
-
-  return strcmp(name1, name2);
+  return strcmp(
+      sg_host_get_name(*(sg_host_t *) n1),
+      sg_host_get_name(*(sg_host_t *) n2)
+  );
 }
 
 int main(int argc, char **argv)
@@ -36,13 +35,13 @@ int main(int argc, char **argv)
 
   /* Check our arguments */
   xbt_assert(argc > 2, "Usage: %s platform_file dax_file [jedule_file]\n"
-            "\tExample: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed", 
-            argv[0], argv[0]);
+       "\tExample: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed", 
+       argv[0], argv[0]);
 
   char *last = strrchr(argv[2], '.');
   char * tracefilename = bprintf("%.*s.trace",(int) (last == NULL ? 
-                                                  strlen(argv[2]) : 
-                                                  last - argv[2]), argv[2]);  
+               strlen(argv[2]) : 
+               last - argv[2]), argv[2]);  
   if (argc == 4)
     tracefilename = xbt_strdup(argv[3]);
  
@@ -76,17 +75,16 @@ int main(int argc, char **argv)
   /* Schedule them all on the first workstation */
   XBT_INFO("------------------- Schedule tasks ---------------------------");
   const sg_host_t *ws_list = sg_host_list();
-  int totalHosts = sg_host_count();
-  qsort((void *) ws_list, totalHosts, sizeof(sg_host_t),
+  int hosts_count = sg_host_count();
+  qsort((void *) ws_list, hosts_count, sizeof(sg_host_t),
         name_compare_hosts);
 
-  int count = sg_host_count();
   xbt_dynar_foreach(dax, cursor, task) {
     if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
       if (!strcmp(SD_task_get_name(task), "end"))
         SD_task_schedulel(task, 1, ws_list[0]);
       else
-        SD_task_schedulel(task, 1, ws_list[cursor % count]);
+        SD_task_schedulel(task, 1, ws_list[cursor % hosts_count]);
     }
   }