Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Check what happens when splitting empty strings, and fix the resulting bug
[simgrid.git] / src / xbt / xbt_str.c
index dfe4f28..83deab8 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);