From 9c2ed0550d02711b073544351a531148be88e96f Mon Sep 17 00:00:00 2001 From: elbachir-one Date: Tue, 24 Jun 2025 18:37:19 +0100 Subject: Add window validity checks to swallow and unswallow functions - Verify `swallowed->win` before resizing to avoid potential crashes with invalid windows. - Updated `unswallow_window` to verify `swallower->win` before mapping, raising, and focusing. - Prevents undefined behavior when client windows are not properly initialized. --- src/sxwm.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/sxwm.c b/src/sxwm.c index 7c789de..61a03be 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -1,17 +1,17 @@ /* - * See LICENSE for more info + * See LICENSE for more info * - * simple xorg window manager - * sxwm is a user-friendly, easily configurable yet powerful - * tiling window manager inspired by window managers such as - * DWM and i3. + * simple xorg window manager + * sxwm is a user-friendly, easily configurable yet powerful + * tiling window manager inspired by window managers such as + * DWM and i3. * - * The userconfig is designed to be as user-friendly as - * possible, and I hope it is easy to configure even without - * knowledge of C or programming, although most people who - * will use this will probably be programmers :) + * The userconfig is designed to be as user-friendly as + * possible, and I hope it is easy to configure even without + * knowledge of C or programming, although most people who + * will use this will probably be programmers :) * - * (C) Abhinav Prasai 2025 + * (C) Abhinav Prasai 2025 */ #include @@ -1036,7 +1036,10 @@ void swallow_window(Client *swallower, Client *swallowed) swallowed->y = swallower->y; swallowed->w = swallower->w; swallowed->h = swallower->h; - XMoveResizeWindow(dpy, swallowed->win, swallowed->x, swallowed->y, swallowed->w, swallowed->h); + + if (swallowed->win) { + XMoveResizeWindow(dpy, swallowed->win, swallowed->x, swallowed->y, swallowed->w, swallowed->h); + } } tile(); @@ -2575,12 +2578,14 @@ void unswallow_window(Client *c) swallower->swallowed = NULL; c->swallower = NULL; - XMapWindow(dpy, swallower->win); - swallower->mapped = True; + if (swallower->win) { + XMapWindow(dpy, swallower->win); + swallower->mapped = True; - focused = swallower; - XSetInputFocus(dpy, swallower->win, RevertToPointerRoot, CurrentTime); - XRaiseWindow(dpy, swallower->win); + focused = swallower; + XSetInputFocus(dpy, swallower->win, RevertToPointerRoot, CurrentTime); + XRaiseWindow(dpy, swallower->win); + } tile(); update_borders(); -- cgit v1.2.3