Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
adapt the prototypes of the declaration to the prototypes of the definition
[simgrid.git] / src / xbt / xbt_str.c
index dfe4f28..2ca23ab 100644 (file)
@@ -350,6 +350,7 @@ XBT_TEST_UNIT("xbt_str_split_quoted",test_split_quoted, "test the function xbt_s
   xbt_dynar_t d;
   char *s;
 
+  mytest("Empty", "", "");
   mytest("Basic test", "toto tutu", "totoXXXtutu");
   mytest("Useless backslashes", "\\t\\o\\t\\o \\t\\u\\t\\u", "totoXXXtutu");
   mytest("Protected space", "toto\\ tutu", "toto tutu");
@@ -372,6 +373,10 @@ char *xbt_str_join(xbt_dynar_t dyn, const char*sep) {
   int cpt;
   char *cursor;
   char *res,*p;
+  
+  if (!dyn_len)
+    return xbt_strdup("");
+
   /* compute the length */
   xbt_dynar_foreach(dyn,cpt,cursor) {
     len+=strlen(cursor);
@@ -448,6 +453,7 @@ static xbt_matrix_t diff_build_LCS(xbt_dynar_t da, xbt_dynar_t db) {
   xbt_matrix_t C = xbt_matrix_new(xbt_dynar_length(da),xbt_dynar_length(db),
                                  sizeof(int),NULL); 
   int i,j;
+
   /* Compute the LCS */
   /*
     C = array(0..m, 0..n)
@@ -463,11 +469,13 @@ static xbt_matrix_t diff_build_LCS(xbt_dynar_t da, xbt_dynar_t db) {
                 C[i,j] := max(C[i,j-1], C[i-1,j])
     return C[m,n]
          */
-  for (i=0; i<xbt_dynar_length(da); i++) 
-    *((int*) xbt_matrix_get_ptr(C,i,0) ) = 0;
+  if (xbt_dynar_length(db) != 0)
+    for (i=0; i<xbt_dynar_length(da); i++) 
+      *((int*) xbt_matrix_get_ptr(C,i,0) ) = 0;
 
-  for (j=0; j<xbt_dynar_length(db); j++) 
-    *((int*) xbt_matrix_get_ptr(C,0,j) ) = 0;
+  if (xbt_dynar_length(da) != 0)
+    for (j=0; j<xbt_dynar_length(db); j++) 
+      *((int*) xbt_matrix_get_ptr(C,0,j) ) = 0;
 
   for (i=1; i<xbt_dynar_length(da); i++) 
     for (j=1; j<xbt_dynar_length(db); j++) {
@@ -506,7 +514,7 @@ static void diff_build_diff(xbt_dynar_t res,
     topush = bprintf("  %s",xbt_dynar_get_as(da,i,char*));
     xbt_dynar_push(res, &topush);
   } else if (j>=0 && 
-            (i<=0 || xbt_matrix_get_as(C,i,j-1,int) >= xbt_matrix_get_as(C,i-1,j,int))) {
+            (i<=0 ||j==0|| xbt_matrix_get_as(C,i,j-1,int) >= xbt_matrix_get_as(C,i-1,j,int))) {
     diff_build_diff(res,C,da,db,i,j-1);
     topush = bprintf("+ %s",xbt_dynar_get_as(db,j,char*));
     xbt_dynar_push(res,&topush);