diff options
author | Sami Kerola | 2014-12-14 13:28:26 +0100 |
---|---|---|
committer | Sami Kerola | 2014-12-19 10:11:03 +0100 |
commit | 1b7a19ebbb61c608265b552f4426bfe01373b1d0 (patch) | |
tree | ab0fc3b7ab688818a85a4b4b498b09c17fbd6370 /login-utils/chfn.c | |
parent | chfn: rewrite prompt() to use strutils (diff) | |
download | kernel-qcow2-util-linux-1b7a19ebbb61c608265b552f4426bfe01373b1d0.tar.gz kernel-qcow2-util-linux-1b7a19ebbb61c608265b552f4426bfe01373b1d0.tar.xz kernel-qcow2-util-linux-1b7a19ebbb61c608265b552f4426bfe01373b1d0.zip |
chfn: use xasprintf() rather than bunch of strlen() and malloc() calls
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'login-utils/chfn.c')
-rw-r--r-- | login-utils/chfn.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/login-utils/chfn.c b/login-utils/chfn.c index ca6f45670..4746927c8 100644 --- a/login-utils/chfn.c +++ b/login-utils/chfn.c @@ -324,12 +324,8 @@ static int save_new_data(struct finfo *pinfo) pinfo->other = ""; /* create the new gecos string */ - len = (strlen(pinfo->full_name) + strlen(pinfo->office) + - strlen(pinfo->office_phone) + strlen(pinfo->home_phone) + - strlen(pinfo->other) + 4); - gecos = (char *)xmalloc(len + 1); - sprintf(gecos, "%s,%s,%s,%s,%s", pinfo->full_name, pinfo->office, - pinfo->office_phone, pinfo->home_phone, pinfo->other); + len = xasprintf(&gecos, "%s,%s,%s,%s,%s", pinfo->full_name, pinfo->office, + pinfo->office_phone, pinfo->home_phone, pinfo->other); /* remove trailing empty fields (but not subfields of pinfo->other) */ if (!pinfo->other[0]) { @@ -351,6 +347,7 @@ static int save_new_data(struct finfo *pinfo) ("Finger information *NOT* changed. Try again later.\n")); return -1; } + free(gecos); printf(_("Finger information changed.\n")); return 0; } |