summaryrefslogtreecommitdiff
path: root/gladeui/glade-id-allocator.c
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2011-01-03 23:57:18 +0900
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2011-01-03 23:57:18 +0900
commitb1605958ed7ec3058f0d9386c5e899f70a002447 (patch)
tree8e0fa9348c1f865ff7389710e0db9708e4b0eaab /gladeui/glade-id-allocator.c
parent51f4b3f3c44e3393b1b99e238f29b1f783e1d667 (diff)
downloadglade-b1605958ed7ec3058f0d9386c5e899f70a002447.tar.gz
* gladeui/glade-project.c, gladeui/glade-id-allocator.c: Dont index unallocated
memory when releasing a widget name that was never allocated (this can happen for loaded widgets with a number), fixes crash when setting naming policy for glom_developer.glade.
Diffstat (limited to 'gladeui/glade-id-allocator.c')
-rw-r--r--gladeui/glade-id-allocator.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/gladeui/glade-id-allocator.c b/gladeui/glade-id-allocator.c
index b125e897..884b22d5 100644
--- a/gladeui/glade-id-allocator.c
+++ b/gladeui/glade-id-allocator.c
@@ -47,7 +47,7 @@ glade_id_allocator_new (void)
GladeIDAllocator *allocator = g_slice_new (GladeIDAllocator);
allocator->n_words = INITIAL_WORDS;
- allocator->data = g_new (guint32, INITIAL_WORDS);
+ allocator->data = g_new (guint32, INITIAL_WORDS);
memset (allocator->data, 0xff, INITIAL_WORDS * sizeof (guint32));
@@ -150,10 +150,23 @@ glade_id_allocator_allocate (GladeIDAllocator * allocator)
void
glade_id_allocator_release (GladeIDAllocator * allocator, guint id)
{
+ guint word_idx;
+
g_return_if_fail (allocator != NULL);
- id = id > 0 ? id - 1 : 0;
- allocator->data[id >> 5] |= 1 << (id & 31);
+ /* Allocated ids start with 1 */
+ if (id > 0)
+ {
+ id = id - 1;
+ word_idx = id >> 5;
+
+ /* Tollerate releasing ids that were never allocated with the allocator
+ * or are out of range... when we load Glade files with huge numbers it happens
+ * that loaded unallocated ids are out of range
+ */
+ if (word_idx < allocator->n_words)
+ allocator->data[word_idx] |= 1 << (id & 31);
+ }
}
#ifdef GLADE_ID_ALLOCATOR_TEST