Hi Yoann,
The strsep replacement has a bug: when passed an empty set of delimiters,
according to the Linux and BSD manual page the token should be set to
the entire string, and *stringp should be set to NULL (so indicating there
are no more tokens). The implementation in gnulib sets *stringp to the end
of the string, so that strsep will repeatedly, infinitely, yield empty
tokens.
Here is a fix, together with an optimization of the length 1 case.
OK to apply?
2007-02-05 Bruno Haible <[EMAIL PROTECTED]>
* lib/strsep.c (strsep): Fix actions in case of no delimiters.
Optimize search in case of 1 delimiter.
*** lib/strsep.c 26 Jan 2007 22:16:55 -0000 1.5
--- lib/strsep.c 6 Feb 2007 00:40:38 -0000
***************
*** 29,47 ****
char *start = *stringp;
char *ptr;
! if (!start)
return NULL;
! if (!*delim)
! ptr = start + strlen (start);
else
{
! ptr = strpbrk (start, delim);
! if (!ptr)
! {
! *stringp = NULL;
! return start;
! }
}
*ptr = '\0';
--- 29,54 ----
char *start = *stringp;
char *ptr;
! if (start == NULL)
return NULL;
! /* Optimize the case of no delimiters. */
! if (delim[0] == '\0')
! {
! *stringp = NULL;
! return start;
! }
!
! /* Optimize the case of one delimiter. */
! if (delim[1] == '\0')
! ptr = strchr (start, delim[0]);
else
+ /* The general case. */
+ ptr = strpbrk (start, delim);
+ if (ptr == NULL)
{
! *stringp = NULL;
! return start;
}
*ptr = '\0';