Skip to content

Commit

Permalink
Use xstrdup() when possible
Browse files Browse the repository at this point in the history
Suggested-by: Christian Göttsche <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Dec 3, 2022
1 parent 5bd3fc6 commit 49fcdcf
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions libmisc/utmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,11 @@ static void updwtmpx (const char *filename, const struct utmpx *utx)

if ( (NULL != host)
&& ('\0' != host[0])) {
hostname = (char *) xmalloc (strlen (host) + 1);
strcpy (hostname, host);
hostname = xstrdup (host);
#ifdef HAVE_STRUCT_UTMP_UT_HOST
} else if ( (NULL != ut)
&& ('\0' != ut->ut_host[0])) {
hostname = (char *) xmalloc (sizeof (ut->ut_host) + 1);
USTR2STR (hostname, ut->ut_host);
hostname = xstrdup (ut->ut_host);
#endif /* HAVE_STRUCT_UTMP_UT_HOST */
}

Expand Down Expand Up @@ -353,14 +351,12 @@ int setutmp (struct utmp *ut)

if ( (NULL != host)
&& ('\0' != host[0])) {
hostname = (char *) xmalloc (strlen (host) + 1);
strcpy (hostname, host);
hostname = xstrdup (host);
#ifdef HAVE_STRUCT_UTMP_UT_HOST
} else if ( (NULL != ut)
&& (NULL != ut->ut_host)
&& ('\0' != ut->ut_host[0])) {
hostname = (char *) xmalloc (sizeof (ut->ut_host) + 1);
USTR2STR (hostname, ut->ut_host);
hostname = xstrdup (ut->ut_host);
#endif /* HAVE_STRUCT_UTMP_UT_TYPE */
}

Expand Down

0 comments on commit 49fcdcf

Please sign in to comment.