diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-03-08 01:30:51 -0500 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2019-03-08 09:45:22 +0100 |
commit | aa5c3699109f866b1002621f48a11c54562eb572 (patch) | |
tree | 7e77314ba79025223ab1081b0ce2d0ad476c3e14 | |
parent | 2baad6eba6c7f4edd3bc1ca266503920e9789ad0 (diff) |
wlr_output_layout_get_box: handle empty layout
If there were no outputs in the output layout,
wlr_output_layout_get_box would return the box:
{
.x = INT_MIN,
.y = INT_MIN,
.width = INT_MIN - INT_MAX,
.height = INT_MIN - INT_MAX
}
which results in an integer underflow for both the width and height.
This changes the logic to have the box be all zeroes, since an empty
output layout does not have a width or height and the location of
something without a size is irrelevant so this just uses the origin.
-rw-r--r-- | types/wlr_output_layout.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index 553275d7..c0f7134e 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -380,22 +380,24 @@ struct wlr_box *wlr_output_layout_get_box( } } else { // layout extents - int min_x = INT_MAX, min_y = INT_MAX; - int max_x = INT_MIN, max_y = INT_MIN; - wl_list_for_each(l_output, &layout->outputs, link) { - struct wlr_box *box = output_layout_output_get_box(l_output); - - if (box->x < min_x) { - min_x = box->x; - } - if (box->y < min_y) { - min_y = box->y; - } - if (box->x + box->width > max_x) { - max_x = box->x + box->width; - } - if (box->y + box->height > max_y) { - max_y = box->y + box->height; + int min_x = 0, max_x = 0, min_y = 0, max_y = 0; + if (!wl_list_empty(&layout->outputs)) { + min_x = min_y = INT_MAX; + max_x = max_y = INT_MIN; + wl_list_for_each(l_output, &layout->outputs, link) { + struct wlr_box *box = output_layout_output_get_box(l_output); + if (box->x < min_x) { + min_x = box->x; + } + if (box->y < min_y) { + min_y = box->y; + } + if (box->x + box->width > max_x) { + max_x = box->x + box->width; + } + if (box->y + box->height > max_y) { + max_y = box->y + box->height; + } } } |