This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

strsep bug?



Andrzey send a bug report about strsep.  Since he didn't use properly
the glibcbug script and send quoted unprintable text, I had to
edit the report a bit for presentation.

I'm asking for a volunteer to look into the report and comment on it
since I don't have time to check it myself.

Andreas

P.S. Andrezey,

please always use the glibcbug script and send the script directly -
don't try to package the text in another mail, just send it away.
glibcbug is written by the glibc developers and will send the bug
report to the right address.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Message-Id: <19990629215748.A24237@order.if.uj.edu.pl>
Date: Tue, 29 Jun 1999 21:57:48 +0200
From: "Andrzej M. Ostruszka" <ostruszk@order.if.uj.edu.pl>
To: bugs@gnu.org
Subject: Bug in strsep ?!

>Number:         1186
>Category:       libc
>Synopsis:       Bug in strsep ?!
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    libc-gnats
>State:          open
>Class:          sw-bug
>Submitter-Id:   unknown
>Arrival-Date:   Tue Jun 29 16:00:01 EDT 1999
>Last-Modified:  Wed Jun 30 16:04:26 EDT 1999
>Originator:     
>Organization:
>Release:        
>Environment:
>Description:
>How-To-Repeat:
>Fix:
>Audit-Trail:

Responsible-Changed-From-To: gnats-admin->libc-gnats
Responsible-Changed-By: jaeger
Responsible-Changed-When: Wed Jun 30 16:04:10 1999
Responsible-Changed-Why:
A misfiled glibc bug.

Andreas
>Unformatted:

Submitter-Id:  net
Originator:    Andrzej M. Ostruszka
Organization:  Instytut Fizyki, Uniwersytet Jagiellonski (Cracow)
Confidential:  no
Synopsis:      strsep is not skipping leading delimitiers
Severity:      non-critical but annoying
Priority:      medium
Category:      libc
Class:         'sw-bug' or 'doc-bug' but for sure 'change-request'
Release:       libc-2.0.7
Host type: i686-pc-linux-gnu
System: Linux order 2.2.10 #1 Mon Jun 21 17:28:56 CEST 1999 i686 unknown
Architecture: i686

Description:

Hello world (or maybe just Urlich ? -- he's mentioned in BUGS but
glibcbug insists to send to bugs@gnu.org not to drepper@cygnus.com :)),

I've tried to use function strsep from glibc and had problems because it
doesn't work as described in info (which in my opinion is more
reasonable than it works now). If such behavior is in BSD from which it
is derived than there should be another funcion which will work as
written in info.
The problem is:

char *s =3D "  Omega 15";
char delims[] =3D " \t\n"
char *d;

=2E...

d =3D strsep(&s, delims); /* Now d =3D "" not "Omega"!, and s =3D " Omega 1=
5"*/

The problem is that strsep does not skip leading delimitiers like strtok
do.

How-To-Repeat:
        Example above
Fix:
   My humble proposition is below:

--- start ---

--- strsep.c.orig	Tue Mar 24 20:47:19 1998
+++ strsep.c	Tue Jun 29 21:39:39 1999
@@ -41,13 +41,21 @@
 	end =3D NULL;
       else
 	{
-	  if (*begin =3D=3D ch)
-	    end =3D begin;
+	  /* Skip leading delimitier */
+	  while (*begin && *begin =3D=3D ch)
+	    begin++;
+
+	  /* Is there something left ? */
+	  if (*begin)
+	    end =3D strchr(begin, ch);
 	  else
-	    end =3D strchr (begin + 1, ch);
+	    end =3D NULL;
 	}
     }
   else
+    /* Skip leading delimitiers */
+    begin +=3D strspn(begin, delim);
+
     /* Find the end of the token.  */
     end =3D strpbrk (begin, delim);

---end---
					Best regards
--=20
    ____   _  ___
   /  | \_/ |/ _ \		Andrzej Marek Ostruszka
  / _ |     | (_) | Instytut Fizyki, Uniwersytet Jagiellonski (Cracow)
 /_/ L|_|V|_|\___/	(PGP <-- finger ostruszk@order.if.uj.edu.pl)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Message-Id: <19990629224724.A24363@order.if.uj.edu.pl>
Date: Tue, 29 Jun 1999 22:47:24 +0200
From: "Andrzej M. Ostruszka" <ostruszk@order.if.uj.edu.pl>
To: bugs@gnu.org
Subject: strsep patch update :(....

>Number:         1187
>Category:       libc
>Synopsis:       strsep patch update :(....
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    libc-gnats
>State:          open
>Class:          sw-bug
>Submitter-Id:   unknown
>Arrival-Date:   Tue Jun 29 16:50:01 EDT 1999
>Last-Modified:  Wed Jun 30 16:06:00 EDT 1999
>Originator:     
>Organization:
>Release:        
>Environment:
>Description:
>How-To-Repeat:
>Fix:
>Audit-Trail:

Responsible-Changed-From-To: gnats-admin->libc-gnats
Responsible-Changed-By: jaeger
Responsible-Changed-When: Wed Jun 30 16:05:48 1999
Responsible-Changed-Why:
A mis filed glibc bug - followup to PR libc/1186
>Unformatted:
--5mCyUwZo2JvN/JJP
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

I'm sorry for the previous one patch which I think was buggy. Here is
improved (I hope so) version:

--- start ---

--- strsep.c.orig	Tue Mar 24 20:47:19 1998
+++ strsep.c	Tue Jun 29 22:39:26 1999
@@ -41,21 +41,31 @@
 	end =3D NULL;
       else
 	{
-	  if (*begin =3D=3D ch)
-	    end =3D begin;
+	  /* Skip leading delimitier */
+	  while (*begin && *begin =3D=3D ch)
+	    begin++;
+
+	  /* Is there something left */
+	  if (*begin)
+	    end =3D strchr(begin, ch);
 	  else
-	    end =3D strchr (begin + 1, ch);
+	    return (*stringp =3D NULL);
 	}
     }
   else
-    /* Find the end of the token.  */
-    end =3D strpbrk (begin, delim);
-
+    {
+      /* Skip leading delimitiers */
+      begin +=3D strspn(begin, delim);
+      if (*begin)
+	end =3D strpbrk (begin, delim);
+      else
+	return (*stringp =3D NULL);
+    }
   if (end)
     {
       /* Terminate the token and set *STRINGP past NUL character.  */
       *end++ =3D '\0';
-      *stringp =3D end;
+      *stringp =3D *end ? end: NULL;
     }
   else
     /* No more delimiters; this is the last token.  */

--- end ---

But this patch should be also check carefully.

					Best regards
--=20
    ____   _  ___
   /  | \_/ |/ _ \		Andrzej Marek Ostruszka
  / _ |     | (_) | Instytut Fizyki, Uniwersytet Jagiellonski (Cracow)
 /_/ L|_|V|_|\___/	(PGP <-- finger ostruszk@order.if.uj.edu.pl)

--5mCyUwZo2JvN/JJP


-- 
 Andreas Jaeger   aj@arthur.rhein-neckar.de    jaeger@informatik.uni-kl.de
  for pgp-key finger ajaeger@aixd1.rhrk.uni-kl.de

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]