edje_cc: track parts for descriptions, ensure part types match when inheriting
authorMike Blumenkrantz <zmike@osg.samsung.com>
Wed, 16 Dec 2015 19:31:49 +0000 (14:31 -0500)
committerMike Blumenkrantz <zmike@osg.samsung.com>
Wed, 16 Dec 2015 19:31:49 +0000 (14:31 -0500)
since it's now possible to inherit parts, it's possible that inheriting from
a different part type can lead to memory errors in the case where one part
has a larger desc struct than the other

@fix

src/bin/edje/edje_cc_handlers.c

index 245574e..0936141 100644 (file)
@@ -168,6 +168,8 @@ static Eina_List *sequencing_lookups = NULL;
 
 Eina_List *po_files;
 
+static Eina_Hash *desc_hash = NULL;
+
 struct _Edje_Cc_Handlers_Hierarchy_Info
 {  /* Struct that keeps globals value to impl hierarchy */
    Edje_Part_Collection_Directory_Entry *current_de;
@@ -2914,6 +2916,7 @@ ob_collections(void)
      {
         edje_file->collection = eina_hash_string_small_new(NULL);
         edje_collections_lookup = eina_hash_int32_new(NULL);
+        desc_hash = eina_hash_pointer_new(NULL);
      }
 }
 
@@ -5020,6 +5023,7 @@ _part_type_set(unsigned int type)
           {
              new = _edje_part_description_alloc(type, pc->part, ep->name);
              memcpy(new, previous, sizeof (Edje_Part_Description_Common));
+             eina_hash_add(desc_hash, &new, ep);
 
              ep->default_desc = new;
           }
@@ -5029,6 +5033,7 @@ _part_type_set(unsigned int type)
              previous = ep->other.desc[i];
              new = _edje_part_description_alloc(type, pc->part, ep->name);
              memcpy(new, previous, sizeof (Edje_Part_Description_Common));
+             eina_hash_add(desc_hash, &new, ep);
              ep->other.desc[i] = new;
           }
      }
@@ -5091,6 +5096,8 @@ _part_desc_free(Edje_Part_Collection *pc,
 {
    if (!ed) return NULL;
 
+   eina_hash_del_by_key(desc_hash, &ed);
+
    part_lookup_del(pc, &(ed->rel1.id_x));
    part_lookup_del(pc, &(ed->rel1.id_y));
    part_lookup_del(pc, &(ed->rel2.id_x));
@@ -6998,6 +7005,7 @@ ob_collections_group_parts_part_description(void)
    ep = current_part;
 
    ed = _edje_part_description_alloc(ep->type, pc->part, ep->name);
+   eina_hash_add(desc_hash, &ed, ep);
 
    ed->rel1.id_x = -1;
    ed->rel1.id_y = -1;
@@ -7102,7 +7110,7 @@ static void
 st_collections_group_parts_part_description_inherit(void)
 {
    Edje_Part_Collection *pc;
-   Edje_Part *ep;
+   Edje_Part *ep, *parent_ep = NULL;
    Edje_Part_Description_Common *ed, *parent = NULL;
    Edje_Part_Image_Id *iid;
    char *parent_name;
@@ -7114,7 +7122,9 @@ st_collections_group_parts_part_description_inherit(void)
    ed = current_desc;
 
    parent = parent_desc;
-   if (!parent)
+   if (parent)
+     parent_ep = eina_hash_find(desc_hash, &parent);
+   else
      {
         /* inherit may not be used in the default description */
         if (!ep->other.desc_count)
@@ -7220,6 +7230,14 @@ st_collections_group_parts_part_description_inherit(void)
    ed->color_class = STRDUP(ed->color_class);
    ed->map.colors = _copied_map_colors_get(parent);
 
+   if (parent_ep && (parent_ep->type != ep->type))
+     {
+        /* ensure parent's owner is a compatible type of part */
+        if (((ep->type != EDJE_PART_TYPE_TEXT) && (ep->type != EDJE_PART_TYPE_TEXTBLOCK)) ||
+            ((parent_ep->type != EDJE_PART_TYPE_TEXT) && (parent_ep->type != EDJE_PART_TYPE_TEXTBLOCK)))
+          return;
+     }
+
    switch (ep->type)
      {
       case EDJE_PART_TYPE_SPACER: