From owner-svn-src-head@freebsd.org Fri Mar 10 11:56:27 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 409E7D054D8 for ; Fri, 10 Mar 2017 11:56:27 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from nm7-vm0.bullet.mail.ne1.yahoo.com (nm7-vm0.bullet.mail.ne1.yahoo.com [98.138.91.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 155E11991 for ; Fri, 10 Mar 2017 11:56:27 +0000 (UTC) (envelope-from pfg@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1489146980; bh=WPv5L9x9Z73pKqPBNfgK2W+n4slNwMUe+NdAinmE0Vk=; h=Subject:To:References:Cc:From:Date:In-Reply-To:From:Subject; b=CkRGetiQicNskKm3siq70w6j2QWdZDkz8dkGACprbF60Op6o6Sr7YP01ZTKoTZJHnXhE1AxYgEtxrGaJETX49n2KQAEzSj/3RNYquBPN0+dGvwoVNI5+PmoNMA2Cc4vF6abZ3sddlgBfOLhiu4bkYnw26A7fiTuknKP+dTt0afphmt1V5KrVYkqY0Pev4CSEFmw0gAP164wI+GpUuwbLwRoI3/KyM6/gkQnvi/+NUitoPMXanqX/8FgIxDs+B5+cqBxFAjlAEXV/bNUnYf3N0eLyULEya2sxVz7V5ce8H/uLnsqqSOdr1c8jpIH7Yuk4R6HJPUjlewhVwVUiuSuSGQ== Received: from [98.138.100.112] by nm7.bullet.mail.ne1.yahoo.com with NNFMP; 10 Mar 2017 11:56:20 -0000 Received: from [98.138.226.128] by tm103.bullet.mail.ne1.yahoo.com with NNFMP; 10 Mar 2017 11:56:20 -0000 Received: from [127.0.0.1] by smtp215.mail.ne1.yahoo.com with NNFMP; 10 Mar 2017 11:56:20 -0000 X-Yahoo-Newman-Id: 379014.46642.bm@smtp215.mail.ne1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: EHoMW34VM1kV.Hs76RfH5.fxLZuIX8FjqTqx1I2VseXsC2v K4G7fEMHPcm1kxAX9rsa_o1Nb46tkpdKMg8IVM.Kt9cc4uwk.3hsIyFZoJhS jkVJ5XaDG9jJWGpuMFLvrbJvjdoxaZVpOIjsqRhmrXvq45UKPeoWcnADRRMC s507rnNC6E2LhCVTjpYrA__c.hhXjpLly7CdsnGyUZon_KkrAyFfBFI5_.Oi Vf_PzdUOsqZySC0SpPpZmvZNlozQT4dblFMgcrLoUUhi7fz9OMocTPFR2gOs 9tiFqunTkAxW6_OhQGhqfxWgRSje0CuXgxKJwrwKVZoC3rXKm4BMoLXxT0nI HSxjnLZRrBS82lJRRibrPOQfFYRqxMTlhg4q7YC6Qwy3VlBwV5BjQHIrMqZg FPsBFuz0u_wX6R3acrzf0PXVrpndGeS.lBq24kIgeZnfesR4sc1T1spTlfcS BA3anmhvcSddKy3IIcmnRAmIekkXX1wpXVYuZvCQDTUJZlwQhYkFmi4b2iog lD2lcqVw4iZeHyO.o9.C.tcg2iX_J7oeY98_vGG052qjuZwY- X-Yahoo-SMTP: xcjD0guswBAZaPPIbxpWwLcp9Unf Subject: Re: svn commit: r314989 - head/usr.bin/vmstat To: Bruce Evans , Marcelo Araujo References: <201703100449.v2A4neTK046456@repo.freebsd.org> <20170310181404.C1416@besplex.bde.org> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org From: Pedro Giffuni Message-ID: <0906af1d-09aa-fd1e-35cc-9361a68fc160@FreeBSD.org> Date: Fri, 10 Mar 2017 06:59:23 -0500 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20170310181404.C1416@besplex.bde.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 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: Fri, 10 Mar 2017 11:56:27 -0000 On 3/10/2017 2:45 AM, Bruce Evans wrote: > On Fri, 10 Mar 2017, Marcelo Araujo wrote: > >> ... >> Log: >> Use nitems() from sys/param.h and also remove the cast. >> >> Reviewed by: markj >> MFC after: 3 weeks. >> Differential Revision: https://reviews.freebsd.org/D9937 >> ... >> Modified: head/usr.bin/vmstat/vmstat.c >> ============================================================================== >> >> --- head/usr.bin/vmstat/vmstat.c Fri Mar 10 04:30:31 2017 (r314988) >> +++ head/usr.bin/vmstat/vmstat.c Fri Mar 10 04:49:40 2017 (r314989) >> @@ -288,17 +288,13 @@ retry_nlist: >> namelist[X_SUM].n_name = "_cnt"; >> goto retry_nlist; >> } >> - for (c = 0; >> - c < (int)(sizeof(namelist)/sizeof(namelist[0])); >> - c++) >> + for (c = 0; c < nitems(namelist); c++) >> if (namelist[c].n_type == 0) >> bufsize += strlen(namelist[c].n_name) + 1; > > This undoes fixes to compile at WARNS=2 in r87690 and now breaks at > WARNS=3. > vmstat is still compiled at WARNS=1. > > nitems suffers from the same unsigned poisoning as the sizeof() > expression > (since it reduces to the same expression. Casting to int in the > expression > to fix the warning would break exotic cases. Of course, nitems is > undocumented so no one knows when it is supposed to work). > > vmstat compiles with no errors at WARNS=2. At WARNS=3, it used to > compile > with 9 excessive warnings (about the good style of omitting redundant > initializers). Now it compiles with 10 excessive warnings. 1 more about > comparison between signed unsigned. This warning is a compiler bug. > Both > gcc-4.2.1 and clang-3.9.0 have it. It is enabled by -W, which is put in > CFLAGS at WARNS >= 3, or by -Wsign-compare. > > These compilers even complain about: > > int c; > > for (c = 0; c < 1U; c++) > foo(); > > where it is extremely clear that c never gets converted to a wrong value > when it is promoted to unsigned for the comparison. Compilers should > only warn about sign mismatches if they can't figure out the ranges or > if they can figure out the ranges but dangerous promotiions occur. > Compilers do excessive unrolling and other optimizations of loops like > the above, and they must figure out the ranges for this. > I haven't looked at the code but it would seem like you can unsign c and avoid the cast. Pedro.