From 7ca9a10fb53786782135c68308db7111193b6711 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Fri, 29 Dec 2023 18:07:55 +0100 Subject: [PATCH] login: simplify name creation The function xasprintf is simpler to handle than calling xstrncpy and xstrdup for the same task. Introduced buff variable to make the whole else-block look like the if-block. Signed-off-by: Tobias Stoeckmann --- login-utils/login.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/login-utils/login.c b/login-utils/login.c index 82f0cd9f7f..9e9e029889 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -1553,14 +1553,13 @@ int main(int argc, char **argv) child_argv[child_argc++] = "-c"; child_argv[child_argc++] = buff; } else { - char tbuf[PATH_MAX + 2], *p; - - tbuf[0] = '-'; - xstrncpy(tbuf + 1, ((p = strrchr(pwd->pw_shell, '/')) ? - p + 1 : pwd->pw_shell), sizeof(tbuf) - 1); + char *buff, *p; + xasprintf(&buff, "-%.*s", PATH_MAX, + ((p = strrchr(pwd->pw_shell, '/')) ? + p + 1 : pwd->pw_shell)); child_argv[child_argc++] = pwd->pw_shell; - child_argv[child_argc++] = xstrdup(tbuf); + child_argv[child_argc++] = buff; } child_argv[child_argc++] = NULL; -- 2.47.3