From owner-svn-src-head@freebsd.org Mon May 28 05:01:43 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CD18BEF8737; Mon, 28 May 2018 05:01:43 +0000 (UTC) (envelope-from araujo@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 800E67BF42; Mon, 28 May 2018 05:01:43 +0000 (UTC) (envelope-from araujo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6174F941; Mon, 28 May 2018 05:01:43 +0000 (UTC) (envelope-from araujo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4S51hQX046600; Mon, 28 May 2018 05:01:43 GMT (envelope-from araujo@FreeBSD.org) Received: (from araujo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4S51hbH046599; Mon, 28 May 2018 05:01:43 GMT (envelope-from araujo@FreeBSD.org) Message-Id: <201805280501.w4S51hbH046599@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: araujo set sender to araujo@FreeBSD.org using -f From: Marcelo Araujo Date: Mon, 28 May 2018 05:01:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334275 - head/lib/libc/string X-SVN-Group: head X-SVN-Commit-Author: araujo X-SVN-Commit-Paths: head/lib/libc/string X-SVN-Commit-Revision: 334275 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 May 2018 05:01:44 -0000 Author: araujo Date: Mon May 28 05:01:42 2018 New Revision: 334275 URL: https://svnweb.freebsd.org/changeset/base/334275 Log: 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 Modified: head/lib/libc/string/strsep.3 Modified: head/lib/libc/string/strsep.3 ============================================================================== --- head/lib/libc/string/strsep.3 Mon May 28 04:38:10 2018 (r334274) +++ head/lib/libc/string/strsep.3 Mon May 28 05:01:42 2018 (r334275) @@ -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 l char *token, *string, *tofree; tofree = string = strdup("abc,def,ghi"); -assert(string != NULL); +if (string != NULL) + while ((token = strsep(&string, ",")) != NULL) + printf("%s\en", token); -while ((token = strsep(&string, ",")) != NULL) - printf("%s\en", token); - free(tofree); +free(string); .Ed .Pp The following uses