aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorMarcelo Araujo <araujo@FreeBSD.org>2018-05-28 05:01:42 +0000
committerMarcelo Araujo <araujo@FreeBSD.org>2018-05-28 05:01:42 +0000
commit4bee02ad1bdee053e4bbab3107e7ad88ff2bb7e7 (patch)
treedd99257916151653717b336029ab3846df89ce7c /lib/libc
parentfccdefa1a119245bb7fa55602d0b549dd7bdb89f (diff)
downloadsrc-4bee02ad1bdee053e4bbab3107e7ad88ff2bb7e7.tar.gz
src-4bee02ad1bdee053e4bbab3107e7ad88ff2bb7e7.zip
Update strsep(3) EXAMPLE section regards the usage of assert(3).
As many people has pointed out, using assert(3) shall be not the best approach to verify if strdup(3) has allocated memory to string. Reviewed by: imp MFC after: 4 weeks. Sponsored by: iXsystems Inc. Differential Revision: https://reviews.freebsd.org/D15594
Notes
Notes: svn path=/head/; revision=334275
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/string/strsep.310
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/libc/string/strsep.3 b/lib/libc/string/strsep.3
index 4e9dad9db5ae..3013fb3b313e 100644
--- a/lib/libc/string/strsep.3
+++ b/lib/libc/string/strsep.3
@@ -31,7 +31,7 @@
.\" @(#)strsep.3 8.1 (Berkeley) 6/9/93
.\" $FreeBSD$
.\"
-.Dd December 5, 2008
+.Dd May 28, 2018
.Dt STRSEP 3
.Os
.Sh NAME
@@ -86,12 +86,12 @@ to parse a string, and prints each token in separate line:
char *token, *string, *tofree;
tofree = string = strdup("abc,def,ghi");
-assert(string != NULL);
-
-while ((token = strsep(&string, ",")) != NULL)
- printf("%s\en", token);
+if (string != NULL)
+ while ((token = strsep(&string, ",")) != NULL)
+ printf("%s\en", token);
free(tofree);
+free(string);
.Ed
.Pp
The following uses