[PATCH 3/4] compositor: Verify that the maximum number of outputs is not exceeded

Bryce Harrington bryce at osg.samsung.com
Wed Dec 23 21:18:47 PST 2015


output_id_pool is defined as a uint32_t, thus ffs() provides a range of
1-32 available id numbers.  When the 33rd output is enabled, Weston will
set the ID to (unsigned)(-1) and thus lead to some unexpected
behaviors.

I'm not sure what the best way to handle this error would be since this
is in an initialization routine, but at least let's document the
potential error condition with an assert().

Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
 src/compositor.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/compositor.c b/src/compositor.c
index 230fd78..a2a03a7 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -4303,6 +4303,9 @@ weston_output_init(struct weston_output *output, struct weston_compositor *c,
 {
 	struct wl_event_loop *loop;
 
+	/* Verify we haven't reached the limit of 32 available output IDs */
+	assert(ffs(~c->output_id_pool) > 0);
+
 	output->compositor = c;
 	output->x = x;
 	output->y = y;
-- 
1.9.1



More information about the wayland-devel mailing list