summaryrefslogtreecommitdiffstats
path: root/libutil
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2013-01-13 21:28:47 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2013-01-13 21:28:47 +0000
commit0d86b15ef0c0d9eae9e92b51fa74113dcc06c465 (patch)
treebf07dbd49e573174dae6222a6df913282a9e7210 /libutil
parentd9ccd06f07add87bcbe09fff357cea35b18ff21a (diff)
downloadpw-darwin-0d86b15ef0c0d9eae9e92b51fa74113dcc06c465.tar.gz
pw-darwin-0d86b15ef0c0d9eae9e92b51fa74113dcc06c465.tar.zst
pw-darwin-0d86b15ef0c0d9eae9e92b51fa74113dcc06c465.zip
libutil: utilize strsep instead of strcat in a loop in gr_make
Submitted by: Christoph Mallon <christoph.mallon gmx.de>
Diffstat (limited to 'libutil')
-rw-r--r--libutil/gr_util.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/libutil/gr_util.c b/libutil/gr_util.c
index 70a4c03..451a4a4 100644
--- a/libutil/gr_util.c
+++ b/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);
}