diff options
author | pfg <pfg@FreeBSD.org> | 2017-03-15 15:33:32 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2017-03-15 15:33:32 +0000 |
commit | 466bdf25f48f01fdeff163183f0be4fa531d8545 (patch) | |
tree | a0682cafacc7bec83d40c16a438196cb0b1e1dab /lib/libc | |
parent | e3e3811f31a3bd1bc1bc938e1194516e56b666db (diff) | |
download | FreeBSD-src-466bdf25f48f01fdeff163183f0be4fa531d8545.zip FreeBSD-src-466bdf25f48f01fdeff163183f0be4fa531d8545.tar.gz |
MFC r315095, r315096, r315097, r315187:
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.
Unsign setlen: it is local and will never be negative. Having one more bit
for growth is beneficial and it avoids a cast when it's going to be used
for allocation.
Remove unused initialization: "num" is properly defined before use.
Let calloc(3) do the multiplication.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/scandir.c | 19 | ||||
-rw-r--r-- | lib/libc/gen/setmode.c | 4 | ||||
-rw-r--r-- | lib/libc/iconv/citrus_esdb.c | 2 | ||||
-rw-r--r-- | lib/libc/stdlib/getenv.c | 2 |
4 files changed, 13 insertions, 14 deletions
diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index d81acc8..0e99aad 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -82,7 +82,7 @@ scandir(const char *dirname, struct dirent ***namelist, #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 dirent ***namelist, 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 dirent ***namelist, * 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 dirent ***namelist, 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); diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c index 7525567..5f90d0a 100644 --- a/lib/libc/gen/setmode.c +++ b/lib/libc/gen/setmode.c @@ -175,7 +175,7 @@ setmode(const char *p) mode_t mask, perm, permXbits, who; long perml; int equalopdone; - int setlen; + u_int setlen; if (!*p) { errno = EINVAL; @@ -190,7 +190,7 @@ setmode(const char *p) setlen = SET_LEN + 2; - if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL) + if ((set = malloc(setlen * sizeof(BITCMD))) == NULL) return (NULL); saveset = set; endset = set + (setlen - 2); diff --git a/lib/libc/iconv/citrus_esdb.c b/lib/libc/iconv/citrus_esdb.c index 299dd5f..f5989fd 100644 --- a/lib/libc/iconv/citrus_esdb.c +++ b/lib/libc/iconv/citrus_esdb.c @@ -263,8 +263,6 @@ _citrus_esdb_get_list(char ***rlist, size_t *rnum, bool sorted) size_t num; int ret; - num = 0; - ret = _lookup_seq_open(&cla, _PATH_ESDB "/" ESDB_ALIAS, _LOOKUP_CASE_IGNORE); if (ret) diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c index 8451103..35e24a4 100644 --- a/lib/libc/stdlib/getenv.c +++ b/lib/libc/stdlib/getenv.c @@ -342,7 +342,7 @@ __build_env(void) envVarsSize = envVarsTotal * 2; /* Create new environment. */ - envVars = calloc(1, sizeof (*envVars) * envVarsSize); + envVars = calloc(envVarsSize, sizeof(*envVars)); if (envVars == NULL) goto Failure; |