From 4a9e1133c2a88d3d06f9a1d10a76cf0fbc049e8a Mon Sep 17 00:00:00 2001 From: mquinson Date: Wed, 6 Jun 2007 13:02:12 +0000 Subject: [PATCH] Check what happens when splitting empty strings, and fix the resulting bug git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3560 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/xbt/xbt_str.c | 5 +++++ src/xbt_str_unit.c | 1 + 2 files changed, 6 insertions(+) diff --git a/src/xbt/xbt_str.c b/src/xbt/xbt_str.c index dfe4f28d96..83deab85e5 100644 --- a/src/xbt/xbt_str.c +++ b/src/xbt/xbt_str.c @@ -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); diff --git a/src/xbt_str_unit.c b/src/xbt_str_unit.c index 13bbfbe60b..d34d8dcec1 100644 --- a/src/xbt_str_unit.c +++ b/src/xbt_str_unit.c @@ -23,6 +23,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"); -- 2.20.1