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 06/13] getusershell: prefer idx_t for indexes
Date: Fri, 11 Jun 2021 17:25:46 -0700	[thread overview]
Message-ID: <20210612002553.1105537-6-eggert@cs.ucla.edu> (raw)
In-Reply-To: <20210612002553.1105537-1-eggert@cs.ucla.edu>

* lib/getusershell.c (line_size, readname):
Prefer idx_t to size_t for indexes, using idx_t-related allocators.
---
 ChangeLog          |  1 +
 lib/getusershell.c | 10 +++++-----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1fca94c03..84ccb3645 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
 	(icatalloc, enlist, allocmust, dfamust):
 	* lib/exclude.c (struct exclude_pattern, free_exclude_segment)
 	(file_pattern_matches, add_exclude, add_exclude_fp):
+	* lib/getusershell.c (line_size, readname):
 	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/getusershell.c b/lib/getusershell.c
index be8a06845..32acd76c0 100644
--- a/lib/getusershell.c
+++ b/lib/getusershell.c
@@ -43,7 +43,7 @@
 # include "unlocked-io.h"
 #endif
 
-static size_t readname (char **, size_t *, FILE *);
+static idx_t readname (char **, idx_t *, FILE *);
 
 #if ! defined ADDITIONAL_DEFAULT_SHELLS && defined __MSDOS__
 # define ADDITIONAL_DEFAULT_SHELLS \
@@ -70,7 +70,7 @@ static FILE *shellstream = NULL;
 static char *line = NULL;
 
 /* Number of bytes allocated for 'line'. */
-static size_t line_size = 0;
+static idx_t line_size = 0;
 \f
 /* Return an entry from the shells file, ignoring comment lines.
    If the file doesn't exist, use the list in DEFAULT_SHELLS (above).
@@ -137,8 +137,8 @@ endusershell (void)
    Return the number of bytes placed in *NAME
    if some nonempty sequence was found, otherwise 0.  */
 
-static size_t
-readname (char **name, size_t *size, FILE *stream)
+static idx_t
+readname (char **name, idx_t *size, FILE *stream)
 {
   int c;
   size_t name_index = 0;
@@ -150,7 +150,7 @@ readname (char **name, size_t *size, FILE *stream)
   for (;;)
     {
       if (*size <= name_index)
-        *name = x2nrealloc (*name, size, sizeof **name);
+        *name = xpalloc (*name, size, 1, -1, sizeof **name);
       if (c == EOF || isspace (c))
         break;
       (*name)[name_index++] = c;
-- 
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 ` Paul Eggert [this message]
2021-06-12  0:25 ` [PATCH 07/13] linebuffer: prefer idx_t for indexes Paul Eggert
2021-06-12  0:25 ` [PATCH 08/13] readtokens: " Paul Eggert
2021-06-12  0:25 ` [PATCH 09/13] readutmp: " Paul Eggert
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-6-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).