--- a/libpurple/imgstore.c Mon Mar 31 21:23:57 2008 +0000 +++ b/libpurple/imgstore.c Mon Apr 28 00:01:07 2008 +0000 @@ -34,11 +34,9 @@ #include "util.h" static GHashTable *imgstore; -static int nextid = 0; +static unsigned int nextid = 0; -/** - * Stored image - * +/* * NOTE: purple_imgstore_add() creates these without zeroing the memory, so * NOTE: make sure to update that function when adding members. */ @@ -91,7 +89,14 @@ { PurpleStoredImage *img = purple_imgstore_add(data, size, filename); if (img) { - img->id = ++nextid; + /* + * Use the next unused id number. We do it in a loop on the + * off chance that nextid wraps back around to 0 and the hash + * table still contains entries from the first time around. + */ + do { + img->id = ++nextid; + } while (img->id == 0 || g_hash_table_lookup(imgstore, &(img->id)) != NULL); g_hash_table_insert(imgstore, &(img->id), img); }