From owner-svn-src-head@freebsd.org Sun Sep 27 23:15:28 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 016A23758F6; Sun, 27 Sep 2020 23:15:28 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4C01hv5L3Jz4XgP; Sun, 27 Sep 2020 23:15:27 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 08RNFJ9r013434 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 28 Sep 2020 02:15:22 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 08RNFJ9r013434 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 08RNFJOb013432; Mon, 28 Sep 2020 02:15:19 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 28 Sep 2020 02:15:19 +0300 From: Konstantin Belousov To: Alan Somers Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r366207 - head/lib/libc/gen Message-ID: <20200927231519.GI2643@kib.kiev.ua> References: <202009272226.08RMQf1h054050@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202009272226.08RMQf1h054050@repo.freebsd.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 4C01hv5L3Jz4XgP X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 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: Sun, 27 Sep 2020 23:15:28 -0000 On Sun, Sep 27, 2020 at 10:26:41PM +0000, Alan Somers wrote: > Author: asomers > Date: Sun Sep 27 22:26:41 2020 > New Revision: 366207 > URL: https://svnweb.freebsd.org/changeset/base/366207 > > Log: > Misc compiler warning fixes in lib/libc > > Reviewed by: kevans, imp > MFC after: 2 weeks > Differential Revision: https://reviews.freebsd.org/D26534 > > Modified: > head/lib/libc/gen/auxv.c > head/lib/libc/gen/basename_compat.c > head/lib/libc/gen/crypt.c > head/lib/libc/gen/dirname_compat.c > head/lib/libc/gen/fts-compat.c > head/lib/libc/gen/ftw-compat11.c > head/lib/libc/gen/getentropy.c > > Modified: head/lib/libc/gen/auxv.c > ============================================================================== > --- head/lib/libc/gen/auxv.c Sun Sep 27 21:43:19 2020 (r366206) > +++ head/lib/libc/gen/auxv.c Sun Sep 27 22:26:41 2020 (r366207) > @@ -67,7 +67,8 @@ __init_elf_aux_vector(void) > } > > static pthread_once_t aux_once = PTHREAD_ONCE_INIT; > -static int pagesize, osreldate, canary_len, ncpus, pagesizes_len, bsdflags; > +static int pagesize, osreldate, ncpus, bsdflags; > +static size_t canary_len, pagesizes_len; > static int hwcap_present, hwcap2_present; > static char *canary, *pagesizes, *execpath; > static void *ps_strings, *timekeep; > @@ -245,16 +246,21 @@ int > _elf_aux_info(int aux, void *buf, int buflen) > { > int res; > + size_t buflen_; > > __init_elf_aux_vector(); > if (__elf_aux_vector == NULL) > return (ENOSYS); > _once(&aux_once, init_aux); > > + if (buflen < 0) > + return (EINVAL); > + buflen_ = (size_t)buflen; > + > switch (aux) { > case AT_CANARY: > - if (canary != NULL && canary_len >= buflen) { > - memcpy(buf, canary, buflen); > + if (canary != NULL && canary_len >= buflen_) { > + memcpy(buf, canary, buflen_); > memset(canary, 0, canary_len); > canary = NULL; > res = 0; > @@ -267,35 +273,35 @@ _elf_aux_info(int aux, void *buf, int buflen) > else if (buf == NULL) > res = EINVAL; > else { > - if (strlcpy(buf, execpath, buflen) >= buflen) > + if (strlcpy(buf, execpath, buflen_) >= buflen_) > res = EINVAL; > else > res = 0; > } > break; > case AT_HWCAP: > - if (hwcap_present && buflen == sizeof(u_long)) { > + if (hwcap_present && buflen_ == sizeof(u_long)) { > *(u_long *)buf = hwcap; > res = 0; > } else > res = ENOENT; > break; > case AT_HWCAP2: > - if (hwcap2_present && buflen == sizeof(u_long)) { > + if (hwcap2_present && buflen_ == sizeof(u_long)) { > *(u_long *)buf = hwcap2; > res = 0; > } else > res = ENOENT; > break; > case AT_PAGESIZES: > - if (pagesizes != NULL && pagesizes_len >= buflen) { > - memcpy(buf, pagesizes, buflen); > + if (pagesizes != NULL && pagesizes_len >= buflen_) { > + memcpy(buf, pagesizes, buflen_); > res = 0; > } else > res = ENOENT; > break; > case AT_PAGESZ: > - if (buflen == sizeof(int)) { > + if (buflen_ == sizeof(int)) { > if (pagesize != 0) { > *(int *)buf = pagesize; > res = 0; > @@ -305,7 +311,7 @@ _elf_aux_info(int aux, void *buf, int buflen) > res = EINVAL; > break; > case AT_OSRELDATE: > - if (buflen == sizeof(int)) { > + if (buflen_ == sizeof(int)) { > if (osreldate != 0) { > *(int *)buf = osreldate; > res = 0; > @@ -315,7 +321,7 @@ _elf_aux_info(int aux, void *buf, int buflen) > res = EINVAL; > break; > case AT_NCPUS: > - if (buflen == sizeof(int)) { > + if (buflen_ == sizeof(int)) { > if (ncpus != 0) { > *(int *)buf = ncpus; > res = 0; > @@ -325,7 +331,7 @@ _elf_aux_info(int aux, void *buf, int buflen) > res = EINVAL; > break; > case AT_TIMEKEEP: > - if (buflen == sizeof(void *)) { > + if (buflen_ == sizeof(void *)) { > if (timekeep != NULL) { > *(void **)buf = timekeep; > res = 0; > @@ -335,14 +341,14 @@ _elf_aux_info(int aux, void *buf, int buflen) > res = EINVAL; > break; > case AT_BSDFLAGS: > - if (buflen == sizeof(int)) { > + if (buflen_ == sizeof(int)) { > *(int *)buf = bsdflags; > res = 0; > } else > res = EINVAL; > break; > case AT_PS_STRINGS: > - if (buflen == sizeof(void *)) { > + if (buflen_ == sizeof(void *)) { > if (ps_strings != NULL) { > *(void **)buf = ps_strings; > res = 0; This is significant uglification of the code in the name of fixing pointless warnings. I suspect that you tried to shut down warning about comparision of integers of different size, int vs. sizeof() which has size_t result. Is there anything else ? All these values should be small integers, which is quite vividly illustrated by comparision with sizeof() of built-in types. If compiler cannot deduce that itself the warning should be forcibly disabled by flag instead of doing 'buflen_'. And canary_len/pagesizes_len do not need to take 8 bytes, their values never become greater than one hundred.