From owner-svn-src-all@freebsd.org Mon Jun 4 18:47:15 2018 Return-Path: Delivered-To: svn-src-all@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 98BA2FE11DB; Mon, 4 Jun 2018 18:47:15 +0000 (UTC) (envelope-from cem@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 4C2B77F32F; Mon, 4 Jun 2018 18:47:15 +0000 (UTC) (envelope-from cem@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 29CE1114BE; Mon, 4 Jun 2018 18:47:15 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w54IlFfR095422; Mon, 4 Jun 2018 18:47:15 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w54IlEnb095421; Mon, 4 Jun 2018 18:47:14 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201806041847.w54IlEnb095421@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Mon, 4 Jun 2018 18:47:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334624 - head/sys/libkern X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/sys/libkern X-SVN-Commit-Revision: 334624 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jun 2018 18:47:15 -0000 Author: cem Date: Mon Jun 4 18:47:14 2018 New Revision: 334624 URL: https://svnweb.freebsd.org/changeset/base/334624 Log: str(r)chr: Replace union abuse with __DECONST Writing one union member and reading another is technically illegal C, although we do it in many places in the tree. Use the __DECONST macro instead, which is (technically) a valid C construct. Trivial style(9) cleanups to touched lines while here. Sponsored by: Dell EMC Isilon Modified: head/sys/libkern/strchr.c head/sys/libkern/strrchr.c Modified: head/sys/libkern/strchr.c ============================================================================== --- head/sys/libkern/strchr.c Mon Jun 4 17:49:34 2018 (r334623) +++ head/sys/libkern/strchr.c Mon Jun 4 18:47:14 2018 (r334624) @@ -36,19 +36,16 @@ __FBSDID("$FreeBSD$"); #include char * -strchr(const char *p, int ch) +strchr(const char *cp, int ch) { - union { - const char *cp; - char *p; - } u; + char *p; - u.cp = p; - for (;; ++u.p) { - if (*u.p == ch) - return(u.p); - if (*u.p == '\0') - return(NULL); + p = __DECONST(char *, cp); + for (;; ++p) { + if (*p == ch) + return (p); + if (*p == '\0') + return (NULL); } /* NOTREACHED */ } Modified: head/sys/libkern/strrchr.c ============================================================================== --- head/sys/libkern/strrchr.c Mon Jun 4 17:49:34 2018 (r334623) +++ head/sys/libkern/strrchr.c Mon Jun 4 18:47:14 2018 (r334624) @@ -36,20 +36,16 @@ __FBSDID("$FreeBSD$"); #include char * -strrchr(const char *p, int ch) +strrchr(const char *cp, int ch) { - union { - const char *cp; - char *p; - } u; - char *save; + char *p, *save; - u.cp = p; - for (save = NULL;; ++u.p) { - if (*u.p == ch) - save = u.p; - if (*u.p == '\0') - return(save); + p = __DECONST(char *, cp); + for (save = NULL;; ++p) { + if (*p == ch) + save = p; + if (*p == '\0') + return (save); } /* NOTREACHED */ }