diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-01-20 06:06:49 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-01-20 06:06:49 +0000 |
commit | f8ea4bddcc7fc4f75f754929624bc801a2fc5a6c (patch) | |
tree | 9b8485f53f4c5c43469b56a0e31d87f146b9e388 /lib/libc | |
parent | 7da876cb7a6c1bad0050ced651ea548c4bd16124 (diff) |
Fix the example code. The loop invariant 'i' was not bound by MAXTOKENS
which could result in writing a NUL byte outside of tokens[]. A fix, from
Patrick Latifi, is to move the increment into the "i < MAXTOKENS - 1" block.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/string/strtok.3 | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/libc/string/strtok.3 b/lib/libc/string/strtok.3 index bdf28f68f6d..29eea4847e9 100644 --- a/lib/libc/string/strtok.3 +++ b/lib/libc/string/strtok.3 @@ -29,7 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: strtok.3,v 1.16 2003/06/02 20:18:38 millert Exp $ +.\" $OpenBSD: strtok.3,v 1.17 2004/01/20 06:06:48 millert Exp $ .\" .Dd June 29, 1991 .Dt STRTOK 3 @@ -104,9 +104,9 @@ int i = 0; snprintf(s, sizeof(s), "cat dog horse cow"); for ((p = strtok_r(s, " ", &last)); p; - (p = strtok_r(NULL, " ", &last)), i++) { + (p = strtok_r(NULL, " ", &last))) { if (i < MAXTOKENS - 1) - tokens[i] = p; + tokens[i++] = p; } tokens[i] = NULL; .Ed |