This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/2126] New: strtok doesn't update internal pointer when returning NULL
- From: "fafa at freesurf dot ch" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 9 Jan 2006 11:06:01 -0000
- Subject: [Bug libc/2126] New: strtok doesn't update internal pointer when returning NULL
- Reply-to: sourceware-bugzilla at sourceware dot org
If I call strtok again after it returned NULL (but with a different delimiter)
it does not always return NULL.
Example:
#include <string.h>
int main()
{
const char str[] = "axaaba";
char* token, *cp;
cp = strdup(str);
token = strtok(cp, "ab"); /* token => "x" */
printf("token: %s\n", token ? token : "NULL");
token = strtok(0, "ab"); /* token => NULL */
printf("token: %s\n", token ? token : "NULL");
token = strtok(0, "a"); /* token => "b" ! */
printf("token: %s\n", token ? token : "NULL");
return 0;
}
This program yields the output
token: x
token: NULL
token: b
but it should be
token: x
token: NULL
token: NULL
The error lies in the files sysdeps/i386/strtok.S and
sysdeps/i386/i686/strtok.S. If I take sysdeps/strtok.c the output is correct.
Here is what the standard says:
... The strtok function then searches from there for a character that is
contained in the current separator string. If no such character is found, the
current token extends to the end of the string pointed to by s1, **and
subsequent searches for a token will return a null pointer**.
--
Summary: strtok doesn't update internal pointer when returning
NULL
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: fafa at freesurf dot ch
CC: glibc-bugs at sources dot redhat dot com
GCC build triplet: i486-suse-linux
GCC host triplet: i486-suse-linux
GCC target triplet: i486-suse-linux
http://sourceware.org/bugzilla/show_bug.cgi?id=2126
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.