From 696eeef6b4d9dd7c79a7fde8fbc248c41d4c17cc Mon Sep 17 00:00:00 2001 From: Stanislav Kinsburskiy Date: Thu, 17 Dec 2015 15:29:07 +0300 Subject: [PATCH] mount: use xstrcat() in attach_option() v2: Check for empty string is simplified Signed-off-by: Stanislav Kinsburskiy Signed-off-by: Pavel Emelyanov --- mount.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/mount.c b/mount.c index d26ba07f1..7f3b4974f 100644 --- a/mount.c +++ b/mount.c @@ -1163,24 +1163,11 @@ out: static int attach_option(struct mount_info *pm, char *opt) { - char *buf; - int len, olen; - - len = strlen(pm->options); - olen = strlen(opt); - buf = xrealloc(pm->options, len + olen + 2); - if (buf == NULL) - return -1; - - if (len && buf[len - 1] != ',') { - buf[len] = ','; - len++; - } - - memcpy(buf + len, opt, olen + 1); - pm->options = buf; - - return 0; + if (pm->options[0] == '\0') + pm->options = xstrcat(pm->options, "%s", opt); + else + pm->options = xstrcat(pm->options, ",%s", opt); + return pm->options ? 0 : -1; } /* Is it mounted w or w/o the newinstance option */