From owner-svn-src-all@freebsd.org Fri Mar 10 19:19:36 2017 Return-Path: Delivered-To: svn-src-all@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 51215D0698A; Fri, 10 Mar 2017 19:19:36 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Received: from mail-pf0-x243.google.com (mail-pf0-x243.google.com [IPv6:2607:f8b0:400e:c00::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 202A61F19; Fri, 10 Mar 2017 19:19:36 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Received: by mail-pf0-x243.google.com with SMTP id 67so11745547pfg.2; Fri, 10 Mar 2017 11:19:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=pIWO8zfi58ey9T9Mec9JAxOswpf2UHA5XphSInhrdXE=; b=IQLctTWEzrpMegR3mgxueq57quyI/m/nblNifo4GtijBlPOixOkyKNoJ4Z7wAIk2oY WE/VLmNGUPrKJjxe7ah7Con2022Awg6mwvMtY8q7S+zBzqnVE+WRwa5cW42g8VUKFflS +8Z4H5HPhT7oREFcW4qpHi1I9rD2SU4ZuuYdCcucLnyGHhCloewMSOM9tGk2bFvI24ic CbX7HsT6wphssrsFTt3t0HbKsD+QKmLUYrR7Zh8VmgnUqEzb5SmqVXzQWJXsThHJJKWH Aky7NMP1IT0tCK+60FV+/PTs+wqTL9GfEYFW3XvxpO3xlGa8jPv6/+MXnN+kwFjy4Xyy dr/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=pIWO8zfi58ey9T9Mec9JAxOswpf2UHA5XphSInhrdXE=; b=hF+7zBtRYuX7pOj7slGrFaKQltJycgwotUEFt/2KS8XipLCT2/8/MJ3qn3nR8gaYYf 868a8KJEYCOZWdhb0EHA3HvFe+pIzzo5bznaaS3I8oHsU+Ka5w7lNsPkLz2a/A4Iz+gs 6pnWzNoFROLvmUSQR0trAfKJOuKMhTa8fzQEzv9m62mfXfwnyqDsvseZTrqKeDTtlyy4 P2FDnddVMkNTTJXik86vzBIa5f6OGazqZcVbiuAboium02qB/ojx+bCDEEppTnC8MR7N gnOe/VG9CzZzOsdtlAOC3C6FIePiDmLSl2u9/OB2wpca8O56x6Yx7tX7MWobp4bAhnu2 0ItQ== X-Gm-Message-State: AMke39kKBQ9pNt8mP80in11PuaOjMZ40C0QWE+GGrQnxpZVPKsJJscxKszsbfSWe0Dc/Qg== X-Received: by 10.98.1.10 with SMTP id 10mr22710103pfb.117.1489173575433; Fri, 10 Mar 2017 11:19:35 -0800 (PST) Received: from ?IPv6:2607:fb90:824b:fdcc:bc73:8389:49de:29b7? ([2607:fb90:824b:fdcc:bc73:8389:49de:29b7]) by smtp.gmail.com with ESMTPSA id o26sm20246629pgd.25.2017.03.10.11.19.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Mar 2017 11:19:34 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (1.0) Subject: Re: svn commit: r314989 - head/usr.bin/vmstat From: Ngie Cooper X-Mailer: iPhone Mail (14D27) In-Reply-To: <0906af1d-09aa-fd1e-35cc-9361a68fc160@FreeBSD.org> Date: Fri, 10 Mar 2017 11:19:33 -0800 Cc: Bruce Evans , Marcelo Araujo , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <201703100449.v2A4neTK046456@repo.freebsd.org> <20170310181404.C1416@besplex.bde.org> <0906af1d-09aa-fd1e-35cc-9361a68fc160@FreeBSD.org> To: Pedro Giffuni X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 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: Fri, 10 Mar 2017 19:19:36 -0000 > On Mar 10, 2017, at 03:59, Pedro Giffuni wrote: >=20 >> On 3/10/2017 2:45 AM, Bruce Evans wrote: >>> On Fri, 10 Mar 2017, Marcelo Araujo wrote: >>>=20 >>> ... >>> Log: >>> Use nitems() from sys/param.h and also remove the cast. >>>=20 >>> Reviewed by: markj >>> MFC after: 3 weeks. >>> Differential Revision: https://reviews.freebsd.org/D9937 >>> ... >>> Modified: head/usr.bin/vmstat/vmstat.c >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=20 >>> --- 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 =3D "_cnt"; >>> goto retry_nlist; >>> } >>> - for (c =3D 0; >>> - c < (int)(sizeof(namelist)/sizeof(namelist[0])); >>> - c++) >>> + for (c =3D 0; c < nitems(namelist); c++) >>> if (namelist[c].n_type =3D=3D 0) >>> bufsize +=3D strlen(namelist[c].n_name) + 1; >>=20 >> This undoes fixes to compile at WARNS=3D2 in r87690 and now breaks at WAR= NS=3D3. >> vmstat is still compiled at WARNS=3D1. >>=20 >> nitems suffers from the same unsigned poisoning as the sizeof() expressio= n >> (since it reduces to the same expression. Casting to int in the expressi= on >> to fix the warning would break exotic cases. Of course, nitems is >> undocumented so no one knows when it is supposed to work). >>=20 >> vmstat compiles with no errors at WARNS=3D2. At WARNS=3D3, it used to co= mpile >> 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. Bot= h >> gcc-4.2.1 and clang-3.9.0 have it. It is enabled by -W, which is put in >> CFLAGS at WARNS >=3D 3, or by -Wsign-compare. >>=20 >> These compilers even complain about: >>=20 >> int c; >>=20 >> for (c =3D 0; c < 1U; c++) >> foo(); >>=20 >> 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. >>=20 >=20 > I haven't looked at the code but it would seem like you can unsign c and a= void the cast. Yeah. This might introduce a domino effect though of changes. Cheers! -Ngie=