Re: oversensible assertion



On Fri, 23 Aug 2002, Owen Taylor wrote:

> 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.

i don't see the point here, there's really no good reason to demand
extra code from the canvas and every other pango_layout_set_text()
user at this point *if* you already support text==NULL
with length=0.

> (Just changing 
> pango_layout_set_text() wouldn't make this stuff work in
> general:
>  
>   if (len < 0)
>     len = strlen (text);

i didn't claim that this is going to work, i'm well aware of
strlen() not handling NULL, but this is completely besides the point.
in your API, you chosed to allow text=NULL and not demand text to
be a valid 0-terminated string if length=0. at that point, it's
simply ridiculous for length<0 to not mean "i don't know the size,
find out yourself" but instead "i don't know the size, however i checked
that text is not NULL since i'm not passing length==0".

> Is certainly present in lots and lots of places;

bad code seen elsewhere is not an excuse, and for the record,
i come across this rather seldomly (if at all, it's usually
surrounded by other code telling me the author either has a
global "don't check for NULL" policy, or didn't know his
pointers anyway).

> and in fact,
> it wouldn't make it work in particular, since you'd just
> transfer the problem to g_utf8_validate().)

really? wow, i actually expected this to be an issue as
simple as length = !text && length < 1 ? 0 : length; since
you already support length==0 && text==NULL, i'm sorry
i didn't grasp the problem in it's full complexity.

> 
> Regards,
>                                         Owen
> 

---
ciaoTJ




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