Hello,

I got a bug when using meltgc_new_split_string (in melt-runtime.c) with a string (argument str) like this one "<sep>mystring<sep>anotherString" with <sep> the separator. The function is not working on a string that start with the separator. I guess this case can happen in real case, for exemple when an user give arguments with a space as a separator.

The function was also not working properly on a string like this one: "firstStr<sep><sep>secondStr".

With the patch, we get a correct list, ignoring the possible presence of a first separator and of separator immediatly followed by another.

I took this opportunity to add a small comment to the function (in the second diff).

ChangeLog

2011-06-21  Pierre Vittet  <pier...@pvittet.com>

        * melt-runtime.c (meltgc_new_split_string): Fix issue.

2011-06-21  Pierre Vittet  <pier...@pvittet.com>

        * melt-runtime.c (meltgc_new_split_string): Add comment.


Pierre Vittet
Index: gcc/melt-runtime.c
===================================================================
--- gcc/melt-runtime.c  (revision 175247)
+++ gcc/melt-runtime.c  (working copy)
@@ -4638,6 +4638,12 @@ meltgc_new_split_string (const char*str, int sep,
     {
       cursep = NULL;
       strv = NULL;
+      /* avoid errors when we have str which starts with the separator or when
+         we have a separator immediatly followed by another one (like
+         'first::second').
+      */
+      while (*pc == sep)
+        pc++;
       if (ISSPACE (sep)) 
          for (cursep=pc; *cursep && !ISSPACE (*cursep); cursep++);
       else
Index: gcc/melt-runtime.c
===================================================================
--- gcc/melt-runtime.c  (revision 175247)
+++ gcc/melt-runtime.c  (working copy)
@@ -4604,7 +4604,8 @@ end:
 #undef str_strv
 }
 
-
+/* Split a string into a list of string value using sep as separating 
character.
+*/
 melt_ptr_t
 meltgc_new_split_string (const char*str, int sep, melt_ptr_t discr_p)
 {

Reply via email to