Re: [patch] serious problem in pango_layout_set_text()



Hi,

Owen Taylor <otaylor redhat com> writes:

> > >   g_return_if_fail (layout != NULL);
> > >   g_return_if_fail (length == 0 || text != NULL);
> > 
> > you allow text == NULL && length == 0 here and this used to work before
> > and cleared the layout. 
> > 
> > >   if (!g_utf8_validate (text, length, &end))
> > >     g_warning ("Invalid UTF8 string passed to pango_layout_set_text()");
> > 
> > g_utf8_validate() does not like text == NULL however and will return FALSE
> > with a warning. 
> > 
> > >   length = end - text;
> > 
> > here you use the undefined value of end which has never been touched by
> > g_utf8_validate() ...
> 
> This is irrelevant. Remember, you got a *Gtk-Criticial*, all future
> bets are off. -)

well, I've got a critical warning because I used the code as documented 
(I take the g_return_foo code as documentation here). This should be 
considered a Pango bug. Otherwise you could simply add

    g_warning ("GTK+ comes with no warranty, all bets are off.");

to gtk_init() and declare GTK+ as bug free ;-)

> > Not sure how this would be fixed best...
> 
>  if (length != 0)
>    {
>      if (!g_utf8_validate (text, length, &end))
>        g_warning ("Invalid UTF8 string passed to pango_layout_set_text()");
>      length = end - text;
>    }
> 
> Or we could make g_utf8_validate accept length == 0 && text == NULL, but that
> doesn't seem all that useful.

I do think it is useful. It would make code dealing with buffers much easier
if you could use g_utf8_validate on the buffer without checking length > 0.
If I call g_utf8_validate() with length == 0, I'd expect it to tell me that
my 0 bytes are valid UTF-8 (at least they are not invalid).


Salut, Sven




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