From: Timm Bäder Date: Wed, 8 Jan 2020 07:58:07 +0000 (+0100) Subject: cssarrayvalue: Don't allocate memory when parsing array values X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~20^2~302 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=9cb2fe5cacd3f1689cf01799ec950c7e30ce5a93;p=gtk4.git cssarrayvalue: Don't allocate memory when parsing array values We probably won't find CSS with more than 128 values in array. --- diff --git a/gtk/gtkcssarrayvalue.c b/gtk/gtkcssarrayvalue.c index 60019fea5c..d1e162fda9 100644 --- a/gtk/gtkcssarrayvalue.c +++ b/gtk/gtkcssarrayvalue.c @@ -411,25 +411,28 @@ _gtk_css_array_value_parse (GtkCssParser *parser, GtkCssValue *(* parse_func) (GtkCssParser *parser)) { GtkCssValue *value, *result; - GPtrArray *values; - - values = g_ptr_array_new (); + GtkCssValue *values[128]; + guint n_values = 0; + guint i; do { value = parse_func (parser); if (value == NULL) { - g_ptr_array_set_free_func (values, (GDestroyNotify) _gtk_css_value_unref); - g_ptr_array_free (values, TRUE); + for (i = 0; i < n_values; i ++) + _gtk_css_value_unref (values[i]); + return NULL; } - g_ptr_array_add (values, value); + values[n_values] = value; + n_values ++; + if (G_UNLIKELY (n_values > G_N_ELEMENTS (values))) + g_error ("Only %d elements in a css array are allowed", (int)G_N_ELEMENTS (values)); } while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA)); - result = _gtk_css_array_value_new_from_array ((GtkCssValue **) values->pdata, values->len); - g_ptr_array_free (values, TRUE); + result = _gtk_css_array_value_new_from_array (values, n_values); return result; }