From owner-svn-src-all@freebsd.org Sun Mar 12 03:22:19 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 9989DD07C7D; Sun, 12 Mar 2017 03:22:19 +0000 (UTC) (envelope-from pfg@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 505AF100B; Sun, 12 Mar 2017 03:22:19 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2C3MIq4016365; Sun, 12 Mar 2017 03:22:18 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2C3MIxW016364; Sun, 12 Mar 2017 03:22:18 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201703120322.v2C3MIxW016364@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Sun, 12 Mar 2017 03:22:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315095 - 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.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: Sun, 12 Mar 2017 03:22:19 -0000 Author: pfg Date: Sun Mar 12 03:22:18 2017 New Revision: 315095 URL: https://svnweb.freebsd.org/changeset/base/315095 Log: libc: small cleanups. Rename nitems to numitems: it shares the anme with an existing macro in sys/params.h. Also initialize the value later which avoids asigning the value if we exit early. Reviewed by: ngie MFC after: 3 days Modified: head/lib/libc/gen/scandir.c Modified: head/lib/libc/gen/scandir.c ============================================================================== --- head/lib/libc/gen/scandir.c Sun Mar 12 02:21:16 2017 (r315094) +++ head/lib/libc/gen/scandir.c Sun Mar 12 03:22:18 2017 (r315095) @@ -82,7 +82,7 @@ scandir(const char *dirname, struct dire #endif { struct dirent *d, *p, **names = NULL; - size_t nitems = 0; + size_t numitems; long arraysz; DIR *dirp; @@ -94,6 +94,7 @@ scandir(const char *dirname, struct dire if (names == NULL) goto fail; + numitems = 0; while ((d = readdir(dirp)) != NULL) { if (select != NULL && !SELECT(d)) continue; /* just selected names */ @@ -112,7 +113,7 @@ scandir(const char *dirname, struct dire * Check to make sure the array has space left and * realloc the maximum size. */ - if (nitems >= arraysz) { + if (numitems >= arraysz) { struct dirent **names2; names2 = (struct dirent **)realloc((char *)names, @@ -124,22 +125,22 @@ scandir(const char *dirname, struct dire names = names2; arraysz *= 2; } - names[nitems++] = p; + names[numitems++] = p; } closedir(dirp); - if (nitems && dcomp != NULL) + if (numitems && dcomp != NULL) #ifdef I_AM_SCANDIR_B - qsort_b(names, nitems, sizeof(struct dirent *), (void*)dcomp); + qsort_b(names, numitems, sizeof(struct dirent *), (void*)dcomp); #else - qsort_r(names, nitems, sizeof(struct dirent *), + qsort_r(names, numitems, sizeof(struct dirent *), &dcomp, alphasort_thunk); #endif *namelist = names; - return (nitems); + return (numitems); fail: - while (nitems > 0) - free(names[--nitems]); + while (numitems > 0) + free(names[--numitems]); free(names); closedir(dirp); return (-1);