bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 11/13] stack: prefer idx_t for indexes


From: Paul Eggert
Subject: [PATCH 11/13] stack: prefer idx_t for indexes
Date: Fri, 11 Jun 2021 17:25:51 -0700

* lib/stack.h (_GL_STACK_TYPE, _GL_STACK_PREFIX):
Prefer idx_t to size_t for indexes, using idx_t-related allocators.
---
 ChangeLog   | 1 +
 lib/stack.h | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 93039a69a..fc3c91d63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,7 @@
        * lib/readtokens.c (readtoken, readtokens):
        * lib/readutmp.c (read_utmp):
        * lib/savedir.c (streamsavedir):
+       * lib/stack.h (_GL_STACK_TYPE, _GL_STACK_PREFIX):
        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/stack.h b/lib/stack.h
index dfd57501f..9c3afe724 100644
--- a/lib/stack.h
+++ b/lib/stack.h
@@ -78,7 +78,7 @@ typedef struct
 {
   GL_STACK_ELEMENT *base;
   size_t size;
-  size_t allocated;
+  idx_t allocated;
 } _GL_STACK_TYPE;
 
 /* Initialize a stack.  */
@@ -119,8 +119,8 @@ GL_STACK_STORAGECLASS void
 _GL_STACK_PREFIX (push) (_GL_STACK_TYPE *stack, GL_STACK_ELEMENT item)
 {
   if (stack->size == stack->allocated)
-    stack->base = x2nrealloc (stack->base, &stack->allocated,
-                              sizeof (GL_STACK_ELEMENT));
+    stack->base = xpalloc (stack->base, &stack->allocated, 1, -1,
+                           sizeof *stack->base);;
   stack->base [stack->size++] = item;
 }
 
-- 
2.30.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]