From 978494f76e110154a3035cb1cdbe92965c5552ce Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 12 Nov 2015 10:31:26 +0100 Subject: mkfs.ubifs: simplify make_path with xasprintf Signed-off-by: Sascha Hauer Reviewed-by: Daniel Walter Signed-off-by: Marc Kleine-Budde Signed-off-by: Richard Weinberger --- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'ubifs-utils') diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index 049219b..a99c613 100644 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c @@ -227,13 +227,9 @@ static char *make_path(const char *dir, const char *name) { char *s; - s = malloc(strlen(dir) + strlen(name) + 2); - if (!s) - return NULL; - strcpy(s, dir); - if (dir[strlen(dir) - 1] != '/') - strcat(s, "/"); - strcat(s, name); + xasprintf(&s, "%s%s%s", + dir, dir[strlen(dir) - 1] == '/' ? "" : "/", name); + return s; } -- cgit v1.2.3