svn commit: r315308 - in stable/11/lib/libc: gen iconv stdlib
Pedro F. Giffuni
pfg at FreeBSD.org
Wed Mar 15 15:33:34 UTC 2017
Author: pfg
Date: Wed Mar 15 15:33:32 2017
New Revision: 315308
URL: https://svnweb.freebsd.org/changeset/base/315308
Log:
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.
Modified:
stable/11/lib/libc/gen/scandir.c
stable/11/lib/libc/gen/setmode.c
stable/11/lib/libc/iconv/citrus_esdb.c
stable/11/lib/libc/stdlib/getenv.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/lib/libc/gen/scandir.c
==============================================================================
--- stable/11/lib/libc/gen/scandir.c Wed Mar 15 14:58:29 2017 (r315307)
+++ stable/11/lib/libc/gen/scandir.c Wed Mar 15 15:33:32 2017 (r315308)
@@ -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);
Modified: stable/11/lib/libc/gen/setmode.c
==============================================================================
--- stable/11/lib/libc/gen/setmode.c Wed Mar 15 14:58:29 2017 (r315307)
+++ stable/11/lib/libc/gen/setmode.c Wed Mar 15 15:33:32 2017 (r315308)
@@ -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);
Modified: stable/11/lib/libc/iconv/citrus_esdb.c
==============================================================================
--- stable/11/lib/libc/iconv/citrus_esdb.c Wed Mar 15 14:58:29 2017 (r315307)
+++ stable/11/lib/libc/iconv/citrus_esdb.c Wed Mar 15 15:33:32 2017 (r315308)
@@ -263,8 +263,6 @@ _citrus_esdb_get_list(char ***rlist, siz
size_t num;
int ret;
- num = 0;
-
ret = _lookup_seq_open(&cla, _PATH_ESDB "/" ESDB_ALIAS,
_LOOKUP_CASE_IGNORE);
if (ret)
Modified: stable/11/lib/libc/stdlib/getenv.c
==============================================================================
--- stable/11/lib/libc/stdlib/getenv.c Wed Mar 15 14:58:29 2017 (r315307)
+++ stable/11/lib/libc/stdlib/getenv.c Wed Mar 15 15:33:32 2017 (r315308)
@@ -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;
More information about the svn-src-stable
mailing list