Bug 151524 - [GTK] Off-by-one error in getStyleContext()
Summary: [GTK] Off-by-one error in getStyleContext()
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: Other
Hardware: PC Linux
: P2 Normal
Assignee: Michael Catanzaro
Depends on:
Reported: 2015-11-20 15:56 PST by Michael Catanzaro
Modified: 2015-11-21 09:00 PST (History)
6 users (show)

See Also:

Patch (2.34 KB, patch)
2015-11-20 15:59 PST, Michael Catanzaro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Catanzaro 2015-11-20 15:56:52 PST
In getStyleContext() in RenderThemeGtk.cpp:

GtkWidgetPath* path = gtk_widget_path_new();
gtk_widget_path_append_type(path, widgetType);
// ...
gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_BUTTON);
gtk_widget_path_iter_add_class(path, 1, "text-button");

Only one widget type was appended to the widget path, so the maximum valid index is 0. This code means to add both style classes to the first widget type in the widget path.

This caused no bug in practice, because when the index is invalid, gtk_widget_path_iter_add_class() automatically changes the index to the last valid position in the widget path -- in this case, 0.
Comment 1 Michael Catanzaro 2015-11-20 15:59:51 PST
Created attachment 266010 [details]
Comment 2 Carlos Garcia Campos 2015-11-21 01:44:21 PST
Comment on attachment 266010 [details]

View in context: https://bugs.webkit.org/attachment.cgi?id=266010&action=review

Good catch, thanks!

> Source/WebCore/rendering/RenderThemeGtk.cpp:178
> -        gtk_widget_path_iter_add_class(path, 1, "text-button");
> +        gtk_widget_path_iter_add_class(path, 0, "text-button");

I guess I understood this as the position of the class, rather than the widget at the given position. Since we always add one widget only, maybe it would be less confusing to use -1 in all cases.
Comment 3 Michael Catanzaro 2015-11-21 08:14:38 PST
Now that I understand how the API works, using 0 seems better to me; I would use -1 when I don't know how long the widget path is.
Comment 4 WebKit Commit Bot 2015-11-21 09:00:06 PST
Comment on attachment 266010 [details]

Clearing flags on attachment: 266010

Committed r192724: <http://trac.webkit.org/changeset/192724>
Comment 5 WebKit Commit Bot 2015-11-21 09:00:10 PST
All reviewed patches have been landed.  Closing bug.