# HG changeset patch # User Mark Doliner # Date 1207271849 0 # Node ID e09650135f04f1563bb24c63acbee0ac3d3949ab # Parent 76af23621e1953c8d1900132dc356c2148c241cb Add a little safety... just in case someone imgstores 13 million or however many images diff -r 76af23621e19 -r e09650135f04 libpurple/imgstore.c --- a/libpurple/imgstore.c Thu Apr 03 23:51:19 2008 +0000 +++ b/libpurple/imgstore.c Fri Apr 04 01:17:29 2008 +0000 @@ -34,7 +34,7 @@ #include "util.h" static GHashTable *imgstore; -static int nextid = 0; +static unsigned int nextid = 0; /* * NOTE: purple_imgstore_add() creates these without zeroing the memory, so @@ -73,7 +73,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); }