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:
@ -1054,14 +1054,10 @@ gtk_css_node_get_junction_sides (GtkCssNode *cssnode)
|
|||||||
static void
|
static void
|
||||||
gtk_css_node_clear_classes (GtkCssNode *cssnode)
|
gtk_css_node_clear_classes (GtkCssNode *cssnode)
|
||||||
{
|
{
|
||||||
const GQuark *classes;
|
if (gtk_css_node_declaration_clear_classes (&cssnode->decl))
|
||||||
guint n_classes, i;
|
|
||||||
|
|
||||||
classes = gtk_css_node_declaration_get_classes (cssnode->decl, &n_classes);
|
|
||||||
|
|
||||||
for (i = 0; i < n_classes; ++i)
|
|
||||||
{
|
{
|
||||||
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;
|
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
|
gboolean
|
||||||
gtk_css_node_declaration_has_class (const GtkCssNodeDeclaration *decl,
|
gtk_css_node_declaration_has_class (const GtkCssNodeDeclaration *decl,
|
||||||
GQuark class_quark)
|
GQuark class_quark)
|
||||||
|
@ -45,6 +45,7 @@ gboolean gtk_css_node_declaration_add_class (GtkCssN
|
|||||||
GQuark class_quark);
|
GQuark class_quark);
|
||||||
gboolean gtk_css_node_declaration_remove_class (GtkCssNodeDeclaration **decl,
|
gboolean gtk_css_node_declaration_remove_class (GtkCssNodeDeclaration **decl,
|
||||||
GQuark class_quark);
|
GQuark class_quark);
|
||||||
|
gboolean gtk_css_node_declaration_clear_classes (GtkCssNodeDeclaration **decl);
|
||||||
gboolean gtk_css_node_declaration_has_class (const GtkCssNodeDeclaration *decl,
|
gboolean gtk_css_node_declaration_has_class (const GtkCssNodeDeclaration *decl,
|
||||||
GQuark class_quark);
|
GQuark class_quark);
|
||||||
const GQuark * gtk_css_node_declaration_get_classes (const GtkCssNodeDeclaration *decl,
|
const GQuark * gtk_css_node_declaration_get_classes (const GtkCssNodeDeclaration *decl,
|
||||||
|
Reference in New Issue
Block a user