diff --git a/src/xfns.c b/src/xfns.c index 70a4b6d5509..f960f36e24d 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -6648,7 +6648,8 @@ Internal use only, use `display-monitor-attributes-list' instead. */) #else i = gdk_screen_get_monitor_at_window (gscreen, gwin); #endif - ASET (monitor_frames, i, Fcons (frame, AREF (monitor_frames, i))); + if (0 <= i && i < n_monitors) + ASET (monitor_frames, i, Fcons (frame, AREF (monitor_frames, i))); } }