Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
wlr_output_layout_get_box: handle empty layout
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RedSoxFan authored and emersion committed Mar 8, 2019
1 parent 2baad6e commit aa5c369
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions types/wlr_output_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit aa5c369

Please sign in to comment.