From 3a9bdfad7b4583f085b2e8157df7796839aa8ae2 Mon Sep 17 00:00:00 2001
From: millert <>
Date: Tue, 20 Jan 2004 06:06:48 +0000
Subject: 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.

---
 src/lib/libc/string/strtok.3 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'src')

diff --git a/src/lib/libc/string/strtok.3 b/src/lib/libc/string/strtok.3
index bdf28f68f6..29eea4847e 100644
--- a/src/lib/libc/string/strtok.3
+++ b/src/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
-- 
cgit v1.2.3-55-g6feb