From 256007442f41cd9c461e62337d8d37bdf3407903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Thu, 3 Dec 2015 18:57:02 +0100 Subject: [PATCH 1/2] Cast unsigned to signed before comparison The values of a Rect are unsigned, but can contain signed values. Using MAX when the value is negative causes incorrect behavior and makes the result stay negative, which is what we wanted to avoid here in the first place. Fix by properly casting the value for the comparison. fixes #2094 --- src/x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/x.c b/src/x.c index f1f971e9..faa892aa 100644 --- a/src/x.c +++ b/src/x.c @@ -783,8 +783,8 @@ void x_push_node(Con *con) { /* Ensure we have valid dimensions for our surface. */ // TODO This is probably a bug in the condition above as we should never enter this path // for height == 0. Also, we should probably handle width == 0 the same way. - int width = MAX(rect.width, 1); - int height = MAX(rect.height, 1); + int width = MAX((int32_t)rect.width, 1); + int height = MAX((int32_t)rect.height, 1); xcb_create_pixmap_checked(conn, win_depth, con->frame_buffer.id, con->frame.id, width, height); draw_util_surface_init(conn, &(con->frame_buffer), con->frame_buffer.id, From 35a4e22f4a94d06d54a2cfca0932bb3906d897f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Thu, 3 Dec 2015 18:59:35 +0100 Subject: [PATCH 2/2] Fail gracefully when the gc cannot be created We now only log an error but do not exit when creating the graphics context fails. While, if this happens, rendering will likely be wrong, this is still better than terminating the user's session entirely due to a rendering problem, potentially causing data loss. relates to #2094 --- libi3/draw_util.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libi3/draw_util.c b/libi3/draw_util.c index e33a9ecb..fa538d1a 100644 --- a/libi3/draw_util.c +++ b/libi3/draw_util.c @@ -47,8 +47,7 @@ void draw_util_surface_init(xcb_connection_t *conn, surface_t *surface, xcb_draw xcb_generic_error_t *error = xcb_request_check(conn, gc_cookie); if (error != NULL) { - ELOG("Could not create graphical context. Error code: %d\n", error->error_code); - exit(EXIT_FAILURE); + ELOG("Could not create graphical context. Error code: %d. Please report this bug.\n", error->error_code); } #ifdef CAIRO_SUPPORT