Bug 281667
| Summary: | [GTK][WPE] Use std::array to store GObject signal and property identifiers | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Adrian Perez <aperez> |
| Component: | WPE WebKit | Assignee: | Adrian Perez <aperez> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | bugs-noreply |
| Priority: | P2 | ||
| Version: | Other | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| See Also: | https://bugs.webkit.org/show_bug.cgi?id=282095 | ||
| Bug Depends on: | 281571 | ||
| Bug Blocks: | |||
Adrian Perez
As per the usual GObject practice, we use the following C-ism when defining
identifiers for object signals and properties, and to store their identifiers
(an “unsigned int” for signals, and a “GParamSpec* for properties):
enum {
PROP_0,
PROP_FOO,
PROP_BAR,
N_PROPERTIES
};
static GParamSpec *sObjProperties[N_PROPERTIES] = { nullptr, };
Then, the sObjProperties array is subscripted in the class initializer at the
moment properties (or signals) are created and installed in the class:
sObjProperties[PROP_FOO] = g_param_spec_...( ... );
sObjProperties[PROP_BAR] = g_param_spec_...( ... );
g_object_class_install_properties(objectClass, N_PROPERTIES, sObjProperties);
Also, notifying of property changes (or signal emission) would index the array
as well:
g_object_notify_by_pspec(objectInstance, sObjProperties[PROP_FOO]);
In both cases this is doing array indexing without bounds checking. We can use
e.g. std::array<GParamSpec*, N_PROPERTIES> in such cases, and reduce the usage
of WTF_ALLOW_UNSAFE_BUFFER_USAGE_{BEGIN,END}.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Adrian Perez
While there are possibilities of making the signals/properties mechanism
more idiomatic and have better type checking (maybe using EnumTraits),
this issue is only about removing unsafe buffer uses.
Adrian Perez
Pull request: https://github.com/WebKit/WebKit/pull/35361
EWS
Committed 285400@main (9d3358a6d868): <https://commits.webkit.org/285400@main>
Reviewed commits have been landed. Closing PR #35361 and removing active labels.