cssnode: Move clear_classes() into the NodeDeclaration

The previous code was crashing when used as the returned classes array
would have been invalid after the first deletion. So if a 2nd class
would be deleted, invalid memory might have been referenced.
This commit is contained in:
Benjamin Otte 2015-09-12 02:58:28 +02:00
parent 6118893a4e
commit 610452dda8
3 changed files with 19 additions and 7 deletions

View File

@ -1054,14 +1054,10 @@ gtk_css_node_get_junction_sides (GtkCssNode *cssnode)
static void
gtk_css_node_clear_classes (GtkCssNode *cssnode)
{
const GQuark *classes;
guint n_classes, i;
classes = gtk_css_node_declaration_get_classes (cssnode->decl, &n_classes);
for (i = 0; i < n_classes; ++i)
if (gtk_css_node_declaration_clear_classes (&cssnode->decl))
{
gtk_css_node_remove_class (cssnode, classes[i]);
gtk_css_node_invalidate (cssnode, GTK_CSS_CHANGE_CLASS);
g_object_notify_by_pspec (G_OBJECT (cssnode), cssnode_properties[PROP_CLASSES]);
}
}

View File

@ -307,6 +307,21 @@ gtk_css_node_declaration_remove_class (GtkCssNodeDeclaration **decl,
return TRUE;
}
gboolean
gtk_css_node_declaration_clear_classes (GtkCssNodeDeclaration **decl)
{
if ((*decl)->n_classes == 0)
return FALSE;
gtk_css_node_declaration_make_writable_resize (decl,
(char *) get_classes (*decl) - (char *) *decl,
0,
sizeof (GQuark) * (*decl)->n_classes);
(*decl)->n_classes = 0;
return TRUE;
}
gboolean
gtk_css_node_declaration_has_class (const GtkCssNodeDeclaration *decl,
GQuark class_quark)

View File

@ -45,6 +45,7 @@ gboolean gtk_css_node_declaration_add_class (GtkCssN
GQuark class_quark);
gboolean gtk_css_node_declaration_remove_class (GtkCssNodeDeclaration **decl,
GQuark class_quark);
gboolean gtk_css_node_declaration_clear_classes (GtkCssNodeDeclaration **decl);
gboolean gtk_css_node_declaration_has_class (const GtkCssNodeDeclaration *decl,
GQuark class_quark);
const GQuark * gtk_css_node_declaration_get_classes (const GtkCssNodeDeclaration *decl,