From c65e1dc8d80c023e1d0af957532fe23e2628a143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Courr=C3=A8ges-Anglas?= Date: Sun, 7 Apr 2013 03:07:35 +0200 Subject: Don't use a flexible array member in struct history_item * They are a c99 feature, which makes it impossible to build ratpoison on some platforms. GCC supports zero-sized arrays, more conservative approaches say to use foo[1], but as brlink says a compiler with aggressive optimization turned on might play nasty tricks. Just use a traditional struct. --- src/history.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/history.c b/src/history.c index 29e1749..89c6699 100644 --- a/src/history.c +++ b/src/history.c @@ -65,7 +65,7 @@ extract_shell_part (const char *p) struct history_item { struct list_head node; - char line[]; + char *line; }; static struct history { @@ -113,7 +113,6 @@ history_add_upto (int history_id, const char *item, size_t max) { struct history *h = histories + history_id; struct history_item *i; - size_t item_len; if (item == NULL || *item == '\0' || isspace(*item)) return; @@ -147,6 +146,7 @@ history_add_upto (int history_id, const char *item, size_t max) break; } list_del (&i->node); + free (i->line); free (i); h->count--; } @@ -154,10 +154,9 @@ history_add_upto (int history_id, const char *item, size_t max) if( max == 0 ) return; - item_len = strlen(item); - i = xmalloc (sizeof(struct history_item) + item_len + 1); + i = xmalloc (sizeof (*i)); + i->line = xstrdup (item); - memcpy (i->line, item, item_len + 1); list_add_tail (&i->node, &h->head); h->count++; } @@ -269,6 +268,7 @@ history_resize (int size) while (h->count >= (size_t)size) { list_first (i, &h->head, node); list_del (&i->node); + free (i->line); free (i); h->count--; } -- cgit v1.2.3