From 8867bd554c6acd508d41f80457bac242a36e61fc Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 13 Oct 2008 09:40:14 +0200 Subject: tag_item: avoid wasting space when struct is unpackable Not all compilers support struct packing, and those that don't shouldn't be punished for it. --- src/tag.h | 2 +- src/tag_pool.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tag.h b/src/tag.h index ba28457ce..2a05d1f34 100644 --- a/src/tag.h +++ b/src/tag.h @@ -44,7 +44,7 @@ extern const char *mpdTagItemKeys[]; struct tag_item { enum tag_type type; - char value[1]; + char value[sizeof(long)]; } mpd_packed; struct tag { diff --git a/src/tag_pool.c b/src/tag_pool.c index 257458795..dc2e0df2b 100644 --- a/src/tag_pool.c +++ b/src/tag_pool.c @@ -69,7 +69,9 @@ static struct slot *slot_alloc(struct slot *next, enum tag_type type, const char *value, int length) { - struct slot *slot = xmalloc(sizeof(*slot) + length); + struct slot *slot; + + slot = xmalloc(sizeof(*slot) - sizeof(slot->item.value) + length + 1); slot->next = next; slot->ref = 1; slot->item.type = type; -- cgit v1.2.3