Patchwork [MELT] fix minor issue with meltgc_new_split_string

login
register
mail settings
Submitter Pierre Vittet
Date June 21, 2011, 4:11 p.m.
Message ID <4E00C295.5060502@pvittet.com>
Download mbox | patch
Permalink /patch/101307/
State New
Headers show

Comments

Pierre Vittet - June 21, 2011, 4:11 p.m.
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  <piervit@pvittet.com>

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

2011-06-21  Pierre Vittet  <piervit@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)
@@ -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)
 {
Basile Starynkevitch - June 21, 2011, 5:31 p.m.
Thanks. I applied both patches:

% svn log --limit 2 gcc/melt-runtime.c
------------------------------------------------------------------------
r175268 | bstarynk | 2011-06-21 19:29:34 +0200 (Tue, 21 Jun 2011) | 6 lines


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

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


------------------------------------------------------------------------
r175267 | bstarynk | 2011-06-21 19:28:57 +0200 (Tue, 21 Jun 2011) | 7 lines


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

	* melt-runtime.c (meltgc_new_split_string): Fix issue with string
	starting with seperator.


------------------------------------------------------------------------

[notice that I changed the ChangeLog comment above]

Cheers.

Patch

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