From e6ca7ca06f585fa22662443275d44a407f366c9d Mon Sep 17 00:00:00 2001 From: Albert Safin Date: Wed, 19 Feb 2020 00:48:31 +0000 Subject: [PATCH] Sanitize con and window rect dimensions Make sure they're neither zero (prohibited by X11) nor overflown during subtraction. --- include/util.h | 1 + src/render.c | 4 ++++ src/util.c | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/include/util.h b/include/util.h index 68b3c68f..8459db10 100644 --- a/include/util.h +++ b/include/util.h @@ -65,6 +65,7 @@ bool rect_contains(Rect rect, uint32_t x, uint32_t y); Rect rect_add(Rect a, Rect b); Rect rect_sub(Rect a, Rect b); bool rect_equals(Rect a, Rect b); +Rect rect_sanitize_dimensions(Rect rect); /** * Returns true if the name consists of only digits. diff --git a/src/render.c b/src/render.c index 112268cc..40704f52 100644 --- a/src/render.c +++ b/src/render.c @@ -64,6 +64,8 @@ void render_con(Con *con) { inset->width -= (2 * con->border_width); inset->height -= (2 * con->border_width); + *inset = rect_sanitize_dimensions(*inset); + /* NB: We used to respect resize increment size hints for tiling * windows up until commit 0db93d9 here. However, since all terminal * emulators cope with ignoring the size hints in a better way than we @@ -121,6 +123,8 @@ void render_con(Con *con) { render_con_dockarea(con, child, ¶ms); } + child->rect = rect_sanitize_dimensions(child->rect); + DLOG("child at (%d, %d) with (%d x %d)\n", child->rect.x, child->rect.y, child->rect.width, child->rect.height); x_raise_con(child); diff --git a/src/util.c b/src/util.c index e9df9575..969dc2a2 100644 --- a/src/util.c +++ b/src/util.c @@ -53,6 +53,12 @@ Rect rect_sub(Rect a, Rect b) { a.height - b.height}; } +Rect rect_sanitize_dimensions(Rect rect) { + rect.width = (int32_t)rect.width <= 0 ? 1 : rect.width; + rect.height = (int32_t)rect.height <= 0 ? 1 : rect.height; + return rect; +} + bool rect_equals(Rect a, Rect b) { return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height; }