libweston: Fix integer underflow in weston_layer_mask_is_infinite
authorAdam Jackson <ajax@redhat.com>
Wed, 16 Oct 2019 20:02:59 +0000 (16:02 -0400)
committerAdam Jackson <ajax@redhat.com>
Wed, 16 Oct 2019 20:02:59 +0000 (16:02 -0400)
ubsan doesn't like what we were doing here:

../libweston/compositor.c:3021:21: runtime error: signed integer overflow: -2147483648 + -1 cannot be represented in type 'int'

Rather than try to be clever in invoking weston_layer_set_mask, just build the
maximal mask explicitly.

libweston/compositor.c

index 63f3880cf030b5d6eeab885d829652dc32877bae..88ca7383d94ed995bdc63db68422fc6ba5cfbe85 100644 (file)
@@ -3030,8 +3030,16 @@ weston_layer_set_mask(struct weston_layer *layer,
 WL_EXPORT void
 weston_layer_set_mask_infinite(struct weston_layer *layer)
 {
-       weston_layer_set_mask(layer, INT32_MIN, INT32_MIN,
-                                    UINT32_MAX, UINT32_MAX);
+       struct weston_view *view;
+
+       layer->mask.x1 = INT32_MIN;
+       layer->mask.x2 = INT32_MAX;
+       layer->mask.y1 = INT32_MIN;
+       layer->mask.y2 = INT32_MAX;
+
+       wl_list_for_each(view, &layer->view_list.link, layer_link.link) {
+               weston_view_geometry_dirty(view);
+       }
 }
 
 WL_EXPORT bool
@@ -3039,8 +3047,8 @@ weston_layer_mask_is_infinite(struct weston_layer *layer)
 {
        return layer->mask.x1 == INT32_MIN &&
               layer->mask.y1 == INT32_MIN &&
-              layer->mask.x2 == INT32_MIN + UINT32_MAX &&
-              layer->mask.y2 == INT32_MIN + UINT32_MAX;
+              layer->mask.x2 == INT32_MAX &&
+              layer->mask.y2 == INT32_MAX;
 }
 
 /**
@@ -7346,7 +7354,7 @@ weston_compositor_shutdown(struct weston_compositor *ec)
  * \ingroup compositor
  */
 WL_EXPORT void
-weston_compositor_exit_with_code(struct weston_compositor *compositor, 
+weston_compositor_exit_with_code(struct weston_compositor *compositor,
                                 int exit_code)
 {
        if (compositor->exit_code == EXIT_SUCCESS)