From: Bruno Haible <bruno@clisp.org>
Date: Tue, 1 Aug 2023 10:58:20 +0000 (+0200)
Subject: readutmp: Trivial simplification.
X-Git-Tag: v1.0~983
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=11054898ce29079b2581977c94e26529342fb001;p=gnulib.git

readutmp: Trivial simplification.

* lib/readutmp.c (extract_trimmed_name): Use constant UT_USER_SIZE.
---

diff --git a/ChangeLog b/ChangeLog
index 48dbeae60b..a96252f2a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-08-01  Bruno Haible  <bruno@clisp.org>
+
+	readutmp: Trivial simplification.
+	* lib/readutmp.c (extract_trimmed_name): Use constant UT_USER_SIZE.
+
 2023-07-31  Bruno Haible  <bruno@clisp.org>
 
 	readutmp tests: Show also the ut_line field.
diff --git a/lib/readutmp.c b/lib/readutmp.c
index 6a5509054e..34b96d999e 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -48,12 +48,12 @@ extract_trimmed_name (const STRUCT_UTMP *ut)
 {
   char *p, *trimmed_name;
 
-  trimmed_name = xmalloc (sizeof (UT_USER (ut)) + 1);
-  strncpy (trimmed_name, UT_USER (ut), sizeof (UT_USER (ut)));
+  trimmed_name = xmalloc (UT_USER_SIZE + 1);
+  strncpy (trimmed_name, UT_USER (ut), UT_USER_SIZE);
   /* Append a trailing NUL.  Some systems pad names shorter than the
      maximum with spaces, others pad with NULs.  Remove any trailing
      spaces.  */
-  trimmed_name[sizeof (UT_USER (ut))] = '\0';
+  trimmed_name[UT_USER_SIZE] = '\0';
   for (p = trimmed_name + strlen (trimmed_name);
        trimmed_name < p && p[-1] == ' ';
        *--p = '\0')