From e514f0128e3470b7e3a4f4701dd5e0da950b281d Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Tue, 5 Nov 2024 12:55:18 -0700 Subject: [PATCH] Ensure a window's monitor is defined when placing it. It is possible that the FvwmWindow monitor is NULL, that can cause a crash when broadcasting the window's configuration to packet modules by referencing a NULL pointer to send the monitor's ID. This now happens with StartsOnPage due to #1076 setting the monitor to NULL initially. This fix ensures that the monitor is always defined after processing any StartsOnScreen settings, by setting it to the current monitor if it is still NULL. Also ensuring the monitor is defined here simplifies some future checks that were doing the same thing by falling back to the current monitor if it was undefined. This fixes the crash reported in #1100. --- fvwm/placement.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/fvwm/placement.c b/fvwm/placement.c index ff82e4b9b..eddffda62 100644 --- a/fvwm/placement.c +++ b/fvwm/placement.c @@ -1804,6 +1804,13 @@ static int _place_window( reason->screen.screen = "current"; } + /* JS: Now that StartsOnScren has been processed, ensure a monitor + * is set here to avoid a possible crash with broadcasting the new + * window and to avoid checking the monitor is defined below. + */ + if (fw->m == NULL) + fw->m = monitor_get_current(); + if (SPLACEMENT_MODE(&pstyle->flags) != PLACE_MINOVERLAPPERCENT && SPLACEMENT_MODE(&pstyle->flags) != PLACE_MINOVERLAP && SPLACEMENT_MODE(&pstyle->flags) != PLACE_POSITION) @@ -1822,8 +1829,7 @@ static int _place_window( /* Don't alter the existing desk location during Capture/Recapture. */ if (!win_opts->flags.do_override_ppos) { - struct monitor *m = fw->m ? fw->m : monitor_get_current(); - fw->Desk = m->virtual_scr.CurrentDesk; + fw->Desk = fw->m->virtual_scr.CurrentDesk; reason->desk.reason = PR_DESK_CURRENT; } else @@ -1832,8 +1838,7 @@ static int _place_window( } if (S_IS_STICKY_ACROSS_DESKS(SFC(pstyle->flags))) { - struct monitor *m = fw->m ? fw->m : monitor_get_current(); - fw->Desk = m->virtual_scr.CurrentDesk; + fw->Desk = fw->m->virtual_scr.CurrentDesk; reason->desk.reason = PR_DESK_STICKY; } else if (SUSE_START_ON_DESK(&pstyle->flags) && start_style.desk && @@ -1930,13 +1935,11 @@ static int _place_window( /* RBW - 11/02/1998 -- I dont. */ if (!is_tracking_shared && !win_opts->flags.do_override_ppos && !DO_NOT_SHOW_ON_MAP(fw)) { - struct monitor *m = fw->m ? fw->m : monitor_get_current(); - - if (m->virtual_scr.CurrentDesk != fw->Desk) + if (fw->m->virtual_scr.CurrentDesk != fw->Desk) { reason->desk.do_switch_desk = 1; } - goto_desk(fw->Desk, m); + goto_desk(fw->Desk, fw->m); } /* Don't move viewport if SkipMapping, or if recapturing the window, * adjust the coordinates later. Otherwise, just switch to the target @@ -1949,8 +1952,6 @@ static int _place_window( { if (start_style.page_x != 0 && start_style.page_y != 0) { - struct monitor *m = (fw && fw->m) ? fw->m : - monitor_get_current(); px = start_style.page_x - 1; py = start_style.page_y - 1; reason->page.reason = PR_PAGE_STYLE; @@ -1959,14 +1960,14 @@ static int _place_window( if (!win_opts->flags.do_override_ppos && !DO_NOT_SHOW_ON_MAP(fw)) { - MoveViewport(m, px,py,True); + MoveViewport(fw->m, px, py, True); reason->page.do_switch_page = 1; } else if (flags.do_honor_starts_on_page) { /* Save the delta from current page */ - pdeltax = m->virtual_scr.Vx - px; - pdeltay = m->virtual_scr.Vy - py; + pdeltax = fw->m->virtual_scr.Vx - px; + pdeltay = fw->m->virtual_scr.Vy - py; reason->page.do_honor_starts_on_page = 1; } }