pidgin: 911e3a3a: Add a little safety... just in case some...
markdoliner at pidgin.im
markdoliner at pidgin.im
Thu Apr 3 21:20:58 EDT 2008
-----------------------------------------------------------------
Revision: 911e3a3a992368fcb0a43a90238092e27a92c581
Ancestor: b39efaac909bd72f3f2632429caa52ca09aaa583
Author: markdoliner at pidgin.im
Date: 2008-04-04T01:17:29
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/911e3a3a992368fcb0a43a90238092e27a92c581
Modified files:
libpurple/imgstore.c
ChangeLog:
Add a little safety... just in case someone imgstores 13 million or
however many images
-------------- next part --------------
============================================================
--- libpurple/imgstore.c a840c1a905bb7fd407eee461535a6f5bb41b2931
+++ libpurple/imgstore.c 57ef5957ecc73e13db3c7b5e62693ee1a2f08ff1
@@ -34,7 +34,7 @@ static GHashTable *imgstore;
#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 @@ purple_imgstore_add_with_id(gpointer dat
{
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);
}
More information about the Commits
mailing list