From owner-svn-src-all@freebsd.org Sun Oct 25 07:42:58 2015 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 0768C8192; Sun, 25 Oct 2015 07:42:58 +0000 (UTC) (envelope-from ngie@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 mx1.freebsd.org (Postfix) with ESMTPS id B834A1C1D; Sun, 25 Oct 2015 07:42:57 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t9P7guWi056062; Sun, 25 Oct 2015 07:42:56 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t9P7gu04056060; Sun, 25 Oct 2015 07:42:56 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201510250742.t9P7gu04056060@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Garrett Cooper Date: Sun, 25 Oct 2015 07:42:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r289925 - head/lib/libc/gen X-SVN-Group: head 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.20 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: Sun, 25 Oct 2015 07:42:58 -0000 Author: ngie Date: Sun Oct 25 07:42:56 2015 New Revision: 289925 URL: https://svnweb.freebsd.org/changeset/base/289925 Log: Fix compiling with gcc [4.2.1] after r287797 when MK_HESOID == no and MK_NIS == no by converting `i` back to an int, and instead cast the loop comparison to `int` The loop comparison is iterating the len(ns_dtab)-1, because the last element is the sentinel tuple { NULL, NULL, NULL, }, so when both HESOID and NIS are off, len(ns_dtab)-1 == 1 - 1 == 0, and the loop is skipped because the expression is tautologically false While here, convert `(sizeof(x) / sizeof(x[0]))` to `nitems(x)` Tested with: clang 3.7.0, gcc 4.2.1, and gcc 4.9.4 [*] with MK_NIS={no,yes} and by running bash -lc 'id -u && id -g && id' * gcc 4.9.4 needs another patch in order for the compile to succeed with -Werror with lib/libc/gen/getgrent.c Reported by: jhibbits Modified: head/lib/libc/gen/getgrent.c head/lib/libc/gen/getpwent.c Modified: head/lib/libc/gen/getgrent.c ============================================================================== --- head/lib/libc/gen/getgrent.c Sun Oct 25 07:26:12 2015 (r289924) +++ head/lib/libc/gen/getgrent.c Sun Oct 25 07:42:56 2015 (r289925) @@ -1239,14 +1239,13 @@ compat_setgrent(void *retval, void *mdat int rv, stayopen; #define set_setent(x, y) do { \ - unsigned int i; \ - \ - for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \ + int i; \ + for (i = 0; i < (int)(nitems(x) - 1); i++) \ x[i].mdata = (void *)y; \ } while (0) rv = compat_getstate(&st); - if (rv != 0) + if (rv != 0) return (NS_UNAVAIL); switch ((enum constants)mdata) { case SETGRENT: @@ -1309,9 +1308,8 @@ compat_group(void *retval, void *mdata, int rv, stayopen, *errnop; #define set_lookup_type(x, y) do { \ - unsigned int i; \ - \ - for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \ + int i; \ + for (i = 0; i < (int)(nitems(x) - 1); i++) \ x[i].mdata = (void *)y; \ } while (0) Modified: head/lib/libc/gen/getpwent.c ============================================================================== --- head/lib/libc/gen/getpwent.c Sun Oct 25 07:26:12 2015 (r289924) +++ head/lib/libc/gen/getpwent.c Sun Oct 25 07:42:56 2015 (r289925) @@ -1607,10 +1607,9 @@ compat_redispatch(struct compat_state *s { NULL, NULL, NULL } }; void *discard; - int rv, e; - unsigned int i; + int e, i, rv; - for (i = 0; i < sizeof(dtab)/sizeof(dtab[0]) - 1; i++) + for (i = 0; i < (int)(nitems(dtab) - 1); i++) dtab[i].mdata = (void *)lookup_how; more: pwd_init(pwd); @@ -1703,9 +1702,8 @@ compat_setpwent(void *retval, void *mdat int rv, stayopen; #define set_setent(x, y) do { \ - unsigned int i; \ - \ - for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \ + int i; \ + for (i = 0; i < (int)(nitems(x) - 1); i++) \ x[i].mdata = (void *)y; \ } while (0)