Skip to content

Commit 46480a1

Browse files
committed
Do not allow setting too small or big scale factors
Add a check to constraint the allowed device scale factors to the [0.05, 5.0] range, ignoring values outside the interval. For debug builds, an assertion will also make it easier for developers to fix bugs in code that calls the function with invalid values. Setting the device scale factor to unreasonably low values can result in divisions by zero, wrong rendering, and/or odd behaviour in general; while for too big values graphics buffers will consume unreasonably big amounts of memory or the maximum usable size for them will result in failure to allocate buffers and content being partially rendered (if at all). Fixes #89
1 parent d4feda6 commit 46480a1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/view-backend.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ wpe_view_backend_dispatch_get_accessible(struct wpe_view_backend* backend)
170170
void
171171
wpe_view_backend_dispatch_set_device_scale_factor(struct wpe_view_backend* backend, float scale)
172172
{
173+
if (scale < 0.05f || scale > 5.0f) {
174+
assert(!"Scale factor not in the [0.05, 5.0] range");
175+
return;
176+
}
177+
173178
if (backend->backend_client && backend->backend_client->set_device_scale_factor)
174179
backend->backend_client->set_device_scale_factor(backend->backend_client_data, scale);
175180
}

0 commit comments

Comments
 (0)