From 7f7ca50d06e4a25c1dabe5c989ed39b36b979cfe Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Mon, 25 Oct 2004 19:53:15 +0000 Subject: [PATCH] - 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. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14760 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/changes | 3 +++ library/string_strtok.c | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) 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. */