[gimp/wip/Jehan/classy-GIMP: 50/50] libgimp: make sure gimp_item_get_by_id() allocates the right class.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/Jehan/classy-GIMP: 50/50] libgimp: make sure gimp_item_get_by_id() allocates the right class.
- Date: Thu, 22 Aug 2019 13:32:33 +0000 (UTC)
commit 92b495c173019432752962ded8c8deb02516d4d5
Author: Jehan <jehan girinstud io>
Date: Mon Aug 19 17:43:43 2019 +0200
libgimp: make sure gimp_item_get_by_id() allocates the right class.
It is theoretically possible for an id to be reused. Normally here this
should not happen, since the previous item would have been removed from
the hash table anyway, when it got destroyed. Let's still be thorough.
libgimp/gimpitem.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
---
diff --git a/libgimp/gimpitem.c b/libgimp/gimpitem.c
index 0785bc80f4..7877cb5a56 100644
--- a/libgimp/gimpitem.c
+++ b/libgimp/gimpitem.c
@@ -172,6 +172,29 @@ gimp_item_get_by_id (gint32 item_id)
item = g_hash_table_lookup (gimp_items,
GINT_TO_POINTER (item_id));
+ if (item)
+ {
+ /* Make sure the item is the proper class, since it could be
+ * reused (which means we'd have cycled over the whole int
+ * range; not that likely yet still possible on a very very
+ * long run process).
+ */
+ if ((_gimp_item_is_layer (item_id) &&
+ ! GIMP_IS_LAYER (item)) ||
+ (_gimp_item_is_layer_mask (item_id) &&
+ ! GIMP_IS_LAYER_MASK (item)) ||
+ (_gimp_item_is_selection (item_id) &&
+ ! GIMP_IS_SELECTION (item)) ||
+ (_gimp_item_is_channel (item_id) &&
+ ! GIMP_IS_CHANNEL (item)) ||
+ (_gimp_item_is_vectors (item_id) &&
+ ! GIMP_IS_VECTORS (item)))
+ {
+ g_hash_table_remove (gimp_items, GINT_TO_POINTER (item_id));
+ item = NULL;
+ }
+ }
+
if (! item)
{
if (_gimp_item_is_layer (item_id))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]