Commit 610452dd authored by Benjamin Otte's avatar Benjamin Otte

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.
parent 6118893a
......@@ -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]);
}
}
......
......@@ -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)
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment