public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre Vittet <piervit@pvittet.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH, MELT] fix minor issue with meltgc_new_split_string
Date: Tue, 21 Jun 2011 16:16:00 -0000	[thread overview]
Message-ID: <4E00C295.5060502@pvittet.com> (raw)

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

             reply	other threads:[~2011-06-21 16:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-21 16:16 Pierre Vittet [this message]
2011-06-21 18:11 ` Basile Starynkevitch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E00C295.5060502@pvittet.com \
    --to=piervit@pvittet.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).