bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: bug-gnulib@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: [PATCH 09/13] readutmp: prefer idx_t for indexes
Date: Fri, 11 Jun 2021 17:25:49 -0700	[thread overview]
Message-ID: <20210612002553.1105537-9-eggert@cs.ucla.edu> (raw)
In-Reply-To: <20210612002553.1105537-1-eggert@cs.ucla.edu>

* lib/readutmp.c (read_utmp):
Prefer idx_t to size_t for indexes, using idx_t-related allocators.
---
 ChangeLog      |  1 +
 lib/readutmp.c | 12 ++++++------
 lib/readutmp.h |  2 ++
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6e2c98014..be79b866c 100644
--- 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.
diff --git a/lib/readutmp.c b/lib/readutmp.c
index 73db856c5..1035a2b8a 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -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);
diff --git a/lib/readutmp.h b/lib/readutmp.h
index 5971e7fd8..a3a7eda01 100644
--- a/lib/readutmp.h
+++ b/lib/readutmp.h
@@ -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);
 
-- 
2.30.2



  parent reply	other threads:[~2021-06-12  0:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-12  0:25 [PATCH 01/13] ialloc: new module Paul Eggert
2021-06-12  0:25 ` [PATCH 02/13] xalloc: new idx_t-based allocators Paul Eggert
2021-06-12  0:25 ` [PATCH 03/13] dirname: prefer idx_t for some indexes Paul Eggert
2021-06-12  0:25 ` [PATCH 04/13] dfa: prefer idx_t for indexes Paul Eggert
2021-06-12  0:25 ` [PATCH 05/13] exclude: prefer idx_t for most indexes Paul Eggert
2021-06-12  0:25 ` [PATCH 06/13] getusershell: prefer idx_t for indexes Paul Eggert
2021-06-12  0:25 ` [PATCH 07/13] linebuffer: " Paul Eggert
2021-06-12  0:25 ` [PATCH 08/13] readtokens: " Paul Eggert
2021-06-12  0:25 ` Paul Eggert [this message]
2021-06-12  0:25 ` [PATCH 10/13] savedir: " Paul Eggert
2021-06-12  0:25 ` [PATCH 11/13] stack: " Paul Eggert
2021-06-13 10:19   ` Bruno Haible
2021-06-13 17:47     ` Paul Eggert
2021-06-12  0:25 ` [PATCH 12/13] userspec: " Paul Eggert
2021-06-12  0:25 ` [PATCH 13/13] xgethostname: " Paul Eggert
2021-06-13 10:05 ` [PATCH 01/13] ialloc: new module Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210612002553.1105537-9-eggert@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).