cssstyle: Don't crash if properties are added at runtime
Just return the default value for those properties. Testcase included. https://bugzilla.redhat.com/show_bug.cgi?id=1281234
This commit is contained in:
committed by
Matthias Clasen
parent
90a1a3c0f4
commit
334893c6c6
@@ -46,9 +46,12 @@ gtk_css_static_style_get_value (GtkCssStyle *style,
|
||||
{
|
||||
GtkCssStaticStyle *sstyle = GTK_CSS_STATIC_STYLE (style);
|
||||
|
||||
if (sstyle->values == NULL ||
|
||||
id >= sstyle->values->len)
|
||||
return NULL;
|
||||
if (G_UNLIKELY (id >= GTK_CSS_PROPERTY_N_PROPERTIES))
|
||||
{
|
||||
GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (id);
|
||||
|
||||
return _gtk_css_style_property_get_initial_value (prop);
|
||||
}
|
||||
|
||||
return g_ptr_array_index (sstyle->values, id);
|
||||
}
|
||||
|
||||
@@ -307,6 +307,29 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
gtk_widget_destroy (window);
|
||||
}
|
||||
|
||||
void
|
||||
test_new_css_property (void)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
GtkStyleContext *context;
|
||||
GtkBorder padding;
|
||||
|
||||
widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_widget_realize (widget);
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
|
||||
gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding);
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
||||
gtk_style_properties_register_property (NULL,
|
||||
g_param_spec_int ("test", "test", "test",
|
||||
0, G_MAXINT, 42, G_PARAM_READWRITE));
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS;
|
||||
|
||||
gtk_style_context_add_class (context, "nonexisting");
|
||||
gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@@ -318,6 +341,7 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/style/match", test_match);
|
||||
g_test_add_func ("/style/basic", test_basic_properties);
|
||||
g_test_add_func ("/style/invalidate-saved", test_invalidate_saved);
|
||||
g_test_add_func ("/style/new-css-property", test_new_css_property);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user