mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-15 23:00:08 +00:00
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:
parent
6118893a4e
commit
610452dda8
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user