From 15b9700547d6667a4e855e30cc7aaf11a2a9908a Mon Sep 17 00:00:00 2001 From: mjg Date: Sun, 13 Jan 2013 21:25:43 +0000 Subject: libutil: eliminate 'found' variable in gr_equal Submitted by: Christoph Mallon --- lib/libutil/gr_util.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'lib/libutil') diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c index acb9767..5e35ebe 100644 --- a/lib/libutil/gr_util.c +++ b/lib/libutil/gr_util.c @@ -346,7 +346,6 @@ gr_equal(const struct group *gr1, const struct group *gr2) { int gr1_ndx; int gr2_ndx; - bool found; /* Check that the non-member information is the same. */ if (gr1->gr_name == NULL || gr2->gr_name == NULL) { @@ -367,17 +366,15 @@ gr_equal(const struct group *gr1, const struct group *gr2) if (gr1->gr_mem != gr2->gr_mem) return (false); } else { - for (found = false, gr1_ndx = 0; gr1->gr_mem[gr1_ndx] != NULL; - gr1_ndx++) { - for (gr2_ndx = 0; gr2->gr_mem[gr2_ndx] != NULL; - gr2_ndx++) + for (gr1_ndx = 0; gr1->gr_mem[gr1_ndx] != NULL; gr1_ndx++) { + for (gr2_ndx = 0;; gr2_ndx++) { + if (gr2->gr_mem[gr2_ndx] == NULL) + return (false); if (strcmp(gr1->gr_mem[gr1_ndx], gr2->gr_mem[gr2_ndx]) == 0) { - found = true; break; } - if (!found) - return (false); + } } /* Check that group2 does not have more members than group1. */ -- cgit v1.1 From c942285112a9fbe906033157e30ef8176d864337 Mon Sep 17 00:00:00 2001 From: mjg Date: Sun, 13 Jan 2013 21:26:57 +0000 Subject: libutil: move group_line_format into the scop of its only user. Submitted by: Christoph Mallon --- lib/libutil/gr_util.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/libutil') diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c index 5e35ebe..70a4c03 100644 --- a/lib/libutil/gr_util.c +++ b/lib/libutil/gr_util.c @@ -50,8 +50,6 @@ static char group_file[PATH_MAX]; static char tempname[PATH_MAX]; static int initialized; -static const char group_line_format[] = "%s:%s:%ju:"; - /* * Initialize statics */ @@ -391,6 +389,7 @@ gr_equal(const struct group *gr1, const struct group *gr2) char * gr_make(const struct group *gr) { + const char *group_line_format = "%s:%s:%ju:"; char *line; size_t line_size; int ndx; -- cgit v1.1 From fecf48554c4a48311d707e584ba242e1a1e8243f Mon Sep 17 00:00:00 2001 From: mjg Date: Sun, 13 Jan 2013 21:28:47 +0000 Subject: libutil: utilize strsep instead of strcat in a loop in gr_make Submitted by: Christoph Mallon --- lib/libutil/gr_util.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/libutil') diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c index 70a4c03..451a4a4 100644 --- a/lib/libutil/gr_util.c +++ b/lib/libutil/gr_util.c @@ -390,7 +390,9 @@ char * gr_make(const struct group *gr) { const char *group_line_format = "%s:%s:%ju:"; + const char *sep; char *line; + char *p; size_t line_size; int ndx; @@ -405,16 +407,18 @@ gr_make(const struct group *gr) } /* Create the group line and fill it. */ - if ((line = malloc(line_size)) == NULL) + if ((line = p = malloc(line_size)) == NULL) return (NULL); - snprintf(line, line_size, group_line_format, gr->gr_name, gr->gr_passwd, + p += sprintf(p, group_line_format, gr->gr_name, gr->gr_passwd, (uintmax_t)gr->gr_gid); - if (gr->gr_mem != NULL) + if (gr->gr_mem != NULL) { + sep = ""; for (ndx = 0; gr->gr_mem[ndx] != NULL; ndx++) { - strcat(line, gr->gr_mem[ndx]); - if (gr->gr_mem[ndx + 1] != NULL) - strcat(line, ","); + p = stpcpy(p, sep); + p = stpcpy(p, gr->gr_mem[ndx]); + sep = ","; } + } return (line); } -- cgit v1.1 From 89fb0f254358fa3cbe1f95560d01fbec42006840 Mon Sep 17 00:00:00 2001 From: mjg Date: Sun, 13 Jan 2013 22:08:18 +0000 Subject: libutil: fix typo in comment for gr_fini. Submitted by: Christoph Mallon --- lib/libutil/gr_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/libutil') diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c index 451a4a4..3f7e199 100644 --- a/lib/libutil/gr_util.c +++ b/lib/libutil/gr_util.c @@ -316,7 +316,7 @@ gr_mkdb(void) } /* - * Clean up. Preserver errno for the caller's convenience. + * Clean up. Preserves errno for the caller's convenience. */ void gr_fini(void) -- cgit v1.1