From 103ffc5b1d139409691fcc6b243d8d669a32085b Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 13 May 2024 15:48:53 +0200 Subject: [PATCH] lib/utmp.c: prepare_utmp(): Use xstrdup() instead of its pattern Signed-off-by: Alejandro Colomar --- lib/utmp.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/utmp.c b/lib/utmp.c index 7834e7a3..40c32c18 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -250,16 +250,12 @@ prepare_utmp(const char *name, const char *line, const char *host, - if ( (NULL != host) - && ('\0' != host[0])) { - hostname = XMALLOC(strlen(host) + 1, char); - strcpy (hostname, host); + if (NULL != host && '\0' != host[0]) + hostname = xstrdup(host); #if defined(HAVE_STRUCT_UTMPX_UT_HOST) - } else if ( (NULL != ut) - && ('\0' != ut->ut_host[0])) { + else if (NULL != ut && '\0' != ut->ut_host[0]) hostname = XSTRNDUP(ut->ut_host); #endif - } if (strncmp(line, "/dev/", 5) == 0) { line += 5;