diff --git a/src/common/coll.c b/src/common/coll.c index 36399d105..b1e946910 100644 --- a/src/common/coll.c +++ b/src/common/coll.c @@ -114,7 +114,11 @@ void CollInsert (Collection* C, void* Item, unsigned Index) if (C->Count >= C->Size) { /* Must grow */ void** NewItems; - C->Size *= 2; + if (C->Size > 0) { + C->Size *= 2; + } else { + C->Size = 8; + } NewItems = xmalloc (C->Size * sizeof (void*)); memcpy (NewItems, C->Items, C->Count * sizeof (void*)); xfree (C->Items); diff --git a/src/common/coll.h b/src/common/coll.h index 6b8f09c8a..9c165799b 100644 --- a/src/common/coll.h +++ b/src/common/coll.h @@ -56,6 +56,9 @@ struct Collection { void** Items; /* Array with dynamic size */ }; +/* Initializer for static collections */ +#define STATIC_COLLECTION_INITIALIZER { 0, 0, 0 } + /*****************************************************************************/ @@ -73,7 +76,7 @@ void DoneCollection (Collection* C); */ Collection* NewCollection (void); -/* Create and return a new collection with the given initial size */ +/* Create and return a new collection */ void FreeCollection (Collection* C); /* Free a collection */