diff --git a/library/changes b/library/changes index 6503ddb..9c53e68 100644 --- a/library/changes +++ b/library/changes @@ -1,3 +1,6 @@ +- strtok() did not terminate properly if the last token in the string + did not end with a separator character but with a '\0' byte. Fixed. + - The directory scanning functions opendir/closedir did not get the global directory data tracking data structure initialized which later led to Enforcer hits and maybe trashed memory. Fixed. diff --git a/library/string_strtok.c b/library/string_strtok.c index 142434d..4e443da 100644 --- a/library/string_strtok.c +++ b/library/string_strtok.c @@ -1,5 +1,5 @@ /* - * $Id: string_strtok.c,v 1.1.1.1 2004-07-26 16:32:20 obarthel Exp $ + * $Id: string_strtok.c,v 1.2 2004-10-25 19:53:15 obarthel Exp $ * * :ts=4 * @@ -89,9 +89,12 @@ strtok(char *str, const char *separator_set) goto out; /* This is where the search can resume later. */ - last = &str[size+1]; - if((*last) == '\0') - last = NULL; + last = &str[size]; + + /* If we didn't hit the end of the string already, + skip the separator. */ + if((*last) != '\0') + last++; /* This is the token we found; make sure that it looks like a valid string. */