From: Tobias Stoeckmann Date: Fri, 29 Dec 2023 17:07:55 +0000 (+0100) Subject: login: simplify name creation X-Git-Tag: v2.40-rc1~55^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ca9a10fb53786782135c68308db7111193b6711;p=thirdparty%2Futil-linux.git 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 --- 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;