]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp: prefer idx_t for indexes
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 12 Jun 2021 00:18:57 +0000 (17:18 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 12 Jun 2021 00:20:12 +0000 (17:20 -0700)
* lib/readutmp.c (read_utmp):
Prefer idx_t to size_t for indexes, using idx_t-related allocators.

ChangeLog
lib/readutmp.c
lib/readutmp.h

index 6e2c980144236505ff1d748f57b1eb96b0ff189b..be79b866c42c4355e0c6b7146fcf8548dac03c78 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,7 @@
        * lib/linebuffer.c (readlinebuffer_delim):
        * lib/linebuffer.h (struct linebuffer):
        * lib/readtokens.c (readtoken, readtokens):
+       * lib/readutmp.c (read_utmp):
        Prefer idx_t to size_t for indexes, and use idx_t-related allocators.
        * lib/basename.c: Do not include xstrndup.h.
        (basename): Simplify by always using memcpy.
index 73db856c5d71ae9b2990ee4dff8d35623105975c..1035a2b8ad829d344cd3fd5a97845e9ed3ec7d70 100644 (file)
@@ -91,8 +91,8 @@ int
 read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
            int options)
 {
-  size_t n_read = 0;
-  size_t n_alloc = 0;
+  idx_t n_read = 0;
+  idx_t n_alloc = 0;
   STRUCT_UTMP *utmp = NULL;
   STRUCT_UTMP *u;
 
@@ -108,7 +108,7 @@ read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
     if (desirable_utmp_entry (u, options))
       {
         if (n_read == n_alloc)
-          utmp = x2nrealloc (utmp, &n_alloc, sizeof *utmp);
+          utmp = xpalloc (utmp, &n_alloc, 1, -1, sizeof *utmp);
 
         utmp[n_read++] = *u;
       }
@@ -127,8 +127,8 @@ int
 read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
            int options)
 {
-  size_t n_read = 0;
-  size_t n_alloc = 0;
+  idx_t n_read = 0;
+  idx_t n_alloc = 0;
   STRUCT_UTMP *utmp = NULL;
   int saved_errno;
   FILE *f = fopen (file, "re");
@@ -139,7 +139,7 @@ read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
   for (;;)
     {
       if (n_read == n_alloc)
-        utmp = x2nrealloc (utmp, &n_alloc, sizeof *utmp);
+        utmp = xpalloc (utmp, &n_alloc, 1, -1, sizeof *utmp);
       if (fread (&utmp[n_read], sizeof utmp[n_read], 1, f) == 0)
         break;
       n_read += desirable_utmp_entry (&utmp[n_read], options);
index 5971e7fd82d7015ce6748eb4f45ebd9d381cca64..a3a7eda01cad4eb8827642841fce41abe3bce85f 100644 (file)
@@ -212,6 +212,8 @@ enum
   };
 
 char *extract_trimmed_name (const STRUCT_UTMP *ut);
+
+/* FIXME: This header should use idx_t, not size_t.  */
 int read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
                int options);