summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-04-07 03:07:35 +0200
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-04-07 03:47:28 +0200
commitc65e1dc8d80c023e1d0af957532fe23e2628a143 (patch)
treef6907a4ffb67adf1cc78325f20530f08a791857e
parentb4149b1b51fd94e0c044a42cc32c2a3bde274e84 (diff)
downloadratpoison-c65e1dc8d80c023e1d0af957532fe23e2628a143.zip
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.
-rw-r--r--src/history.c10
1 files 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--;
}