]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: use xasprintf
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 8 Oct 2023 18:21:04 +0000 (20:21 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 10 Oct 2023 16:55:28 +0000 (18:55 +0200)
It is easier to use xasprintf than performing all its internals
explicitly in login's code base.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
login-utils/login.c

index 36956cce75e302151570836950de82ecf5779341..1f3f5d36c141e0e1535248c8b2d2ff78433846db 100644 (file)
@@ -861,8 +861,7 @@ static void loginpam_err(pam_handle_t *pamh, int retcode)
 static const char *loginpam_get_prompt(struct login_context *cxt)
 {
        const char *host;
-       char *prompt, *dflt_prompt = _("login: ");
-       size_t sz;
+       char *prompt = NULL, *dflt_prompt = _("login: ");
 
        if (cxt->nohost)
                return dflt_prompt;     /* -H on command line */
@@ -873,9 +872,7 @@ static const char *loginpam_get_prompt(struct login_context *cxt)
        if (!(host = get_thishost(cxt, NULL)))
                return dflt_prompt;
 
-       sz = strlen(host) + 1 + strlen(dflt_prompt) + 1;
-       prompt = xmalloc(sz);
-       snprintf(prompt, sz, "%s %s", host, dflt_prompt);
+       xasprintf(&prompt, "%s %s", host, dflt_prompt);
 
        return prompt;
 }