public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, MELT] fix minor issue with meltgc_new_split_string
@ 2011-06-21 16:16 Pierre Vittet
  2011-06-21 18:11 ` Basile Starynkevitch
  0 siblings, 1 reply; 2+ messages in thread
From: Pierre Vittet @ 2011-06-21 16:16 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 940 bytes --]

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

[-- Attachment #2: improve_split_string-175247.diff --]
[-- Type: text/plain, Size: 626 bytes --]

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

[-- Attachment #3: comment_split_string-175247.diff --]
[-- Type: text/plain, Size: 396 bytes --]

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)
 {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH, MELT] fix minor issue with meltgc_new_split_string
  2011-06-21 16:16 [PATCH, MELT] fix minor issue with meltgc_new_split_string Pierre Vittet
@ 2011-06-21 18:11 ` Basile Starynkevitch
  0 siblings, 0 replies; 2+ messages in thread
From: Basile Starynkevitch @ 2011-06-21 18:11 UTC (permalink / raw)
  To: Pierre Vittet; +Cc: gcc-patches

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.
-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-06-21 17:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-21 16:16 [PATCH, MELT] fix minor issue with meltgc_new_split_string Pierre Vittet
2011-06-21 18:11 ` Basile Starynkevitch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).