Re: oversensible assertion



Tim Janik <timj gtk org> writes:

> hey owen,
> 
> the canvas does:
> 
>         case PROP_TEXT:
>                 if (text->text)
>                         g_free (text->text);
> 
>                 text->text = g_value_dup_string (value);
>                 pango_layout_set_text (text->layout, text->text, -1);
> 
>                 text->priv->render_dirty = 1;
>                 break;
> 
> if g_value_dup_string(value) returns NULL, this triggers an assertion
> in pango:
> 
> ** CRITICAL **: file pango-layout.c: line 728 (pango_layout_set_text): assertion `length == 0 || text != NULL' failed
> aborting...
> 
> maybe that assertion should be (length < 1 || text != NULL) ?

I don't think so. There are two cases:

 A) length < 0; text is nul terminated string.
 B) length >= 0; text is an array of characters of length 'length'.

NULL is valid for B, not for A). If the canvas wants to support

  set (item, "text", NULL);

To mean "", it needs to do it explicitely. (Just changing 
pango_layout_set_text() wouldn't make this stuff work in
general:
 
  if (len < 0)
    len = strlen (text);

Is certainly present in lots and lots of places; and in fact,
it wouldn't make it work in particular, since you'd just
transfer the problem to g_utf8_validate().)

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]