From owner-svn-src-head@freebsd.org Mon Sep 28 04:09:02 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 BCDED3F4A88; Mon, 28 Sep 2020 04:09:02 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4C08Cd5gj1z3YC1; Mon, 28 Sep 2020 04:09:01 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-ot1-f49.google.com with SMTP id y5so8384071otg.5; Sun, 27 Sep 2020 21:09:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cP6e29yfbtOc+Dm+GSQjDSpUjDJ6MA6JGG6/FpW8OQc=; b=SNPV236+LuBvntc1FJmkmSOtObWlDED4CQSin9EdgBfKfhjuwDbRpOzTNlVtKVHJAk OKhbFDByI5VGCyo2wcb3EU+4ew8z+juXwGBcgIsbkqYwhNx3JouQHcMh8geWCKKrETx2 W/Bugk/afKcU8ajk6SPnCROSRTh8vYVOcyhkw/X9x13NO2SMj0chU1jDRTbkppMjvW0C Q9QTMK3ZAZGPY6i//bXazcFDNgZGMdu4+7M8KPvhInXgIBBGCMKJ5LR8svrZgvwy0CrW e4E6q4MZ85hLM0th3U2U3Z9z9wH0rlfomYD4Dyv2zN2V6knlnts5YNK+rq8KDQeF0Eq5 Ws7Q== X-Gm-Message-State: AOAM532DvYs+9WO9KcRXjIDlcRjMSKu2OHz0hKkMeR/Wz4St0AzAd1yn NMGulp5xsXqe0Pt81iuLJdGIjorRDLkT5IOj3nU= X-Google-Smtp-Source: ABdhPJzEpmV9ugx0U/f15/EQFBCYYkxQDYlEOcj90tKb65Uvf+Dcc0gNT6/RLuZsm9qeXz34x4tY0S5/pRajB1YfqUU= X-Received: by 2002:a05:6830:1e30:: with SMTP id t16mr7771868otr.18.1601266140389; Sun, 27 Sep 2020 21:09:00 -0700 (PDT) MIME-Version: 1.0 References: <202009272226.08RMQf1h054050@repo.freebsd.org> <20200927231519.GI2643@kib.kiev.ua> In-Reply-To: <20200927231519.GI2643@kib.kiev.ua> From: Alan Somers Date: Sun, 27 Sep 2020 22:08:49 -0600 Message-ID: Subject: Re: svn commit: r366207 - head/lib/libc/gen To: Konstantin Belousov Cc: src-committers , svn-src-all , svn-src-head X-Rspamd-Queue-Id: 4C08Cd5gj1z3YC1 X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of asomers@gmail.com designates 209.85.210.49 as permitted sender) smtp.mailfrom=asomers@gmail.com X-Spamd-Result: default: False [-1.83 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.001]; RCVD_COUNT_TWO(0.00)[2]; FREEFALL_USER(0.00)[asomers]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17:c]; RCVD_TLS_ALL(0.00)[]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; DMARC_NA(0.00)[freebsd.org]; NEURAL_HAM_LONG(-0.99)[-0.991]; RWL_MAILSPIKE_GOOD(0.00)[209.85.210.49:from]; NEURAL_SPAM_SHORT(0.07)[0.065]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; MIME_BASE64_TEXT(0.10)[]; RCVD_IN_DNSWL_NONE(0.00)[209.85.210.49:from]; FREEMAIL_TO(0.00)[gmail.com]; FORGED_SENDER(0.30)[asomers@freebsd.org,asomers@gmail.com]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; MIME_TRACE(0.00)[0:+,1:+,2:~]; FROM_NEQ_ENVFROM(0.00)[asomers@freebsd.org,asomers@gmail.com]; MAILMAN_DEST(0.00)[svn-src-all,svn-src-head] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.33 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: Mon, 28 Sep 2020 04:09:02 -0000 On Sun, Sep 27, 2020 at 5:15 PM Konstantin Belousov wrote: > 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. > Warnings are NOT pointless. 99% of them are. But the only way to find the 1% that aren't is to quell the 99% that are. Last week I wrote a bug that fortunately got caught in code review. But it shouldn't have made it that far. It should've been caught by the compiler, but libc is only built with WARNS=2. This commit is one step towards raising libc's WARNs level to 3. Only 334 files left to go. > > 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 ? > Mostly the warnings were about comparisons of integers with different signedness. Also there were some warnings about missing prototypes. > > 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. > Better to give it enough space that the compiler can check it statically, rather than require runtime checks. -Alan