From 084e964286bfcd13ee6a25a2ee35dfba9da1072e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Mon, 23 Jan 2017 23:14:04 +0100 Subject: Fixes to the previous batch of commits --- liberty-tui.c | 4 +--- liberty.c | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/liberty-tui.c b/liberty-tui.c index 4d48c2a..7cc9bfb 100644 --- a/liberty-tui.c +++ b/liberty-tui.c @@ -194,9 +194,7 @@ row_buffer_space (struct row_buffer *self, int width, chtype attrs) if (width < 0) return; - while (self->chars_len + width >= self->chars_alloc) - self->chars = xreallocarray (self->chars, - sizeof *self->chars, (self->chars_alloc <<= 1)); + ARRAY_RESERVE (self->chars, (size_t) width); struct row_char space = { .attrs = attrs, .c = ' ', .width = 1 }; self->total_width += width; diff --git a/liberty.c b/liberty.c index 86852fd..5ed68da 100644 --- a/liberty.c +++ b/liberty.c @@ -305,17 +305,17 @@ xstrndup (const char *s, size_t n) // The most basic helper macros to make working with arrays not suck -#define ARRAY(type, name) type *name; size_t name ## _len, name ## _size; +#define ARRAY(type, name) type *name; size_t name ## _len, name ## _alloc; #define ARRAY_INIT_SIZED(a, n) \ BLOCK_START \ - (a) = xcalloc (sizeof *(a), (a ## _size) = (n)); \ + (a) = xcalloc (sizeof *(a), (a ## _alloc) = (n)); \ (a ## _len) = 0; \ BLOCK_END #define ARRAY_INIT(a) ARRAY_INIT_SIZED (a, 16) #define ARRAY_RESERVE(a, n) \ BLOCK_START \ - while ((a ## _size) - (a ## _len) < n) \ - (a) = xreallocarray ((a), sizeof *(a), (a ## _size) <<= 1); \ + while ((a ## _alloc) - (a ## _len) < n) \ + (a) = xreallocarray ((a), sizeof *(a), (a ## _alloc) <<= 1); \ BLOCK_END // --- Double-linked list helpers ---------------------------------------------- -- cgit v1.2.3