From xemacs-m  Sat Jun 14 20:59:15 1997
Received: from crystal.WonderWorks.COM (crystal.WonderWorks.com [192.203.206.1])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id UAA08515
	for <xemacs-beta@xemacs.org>; Sat, 14 Jun 1997 20:59:03 -0500 (CDT)
Received: by crystal.WonderWorks.COM 
	id QQctzb28430; Sat, 14 Jun 1997 21:58:42 -0400 (EDT)
Date: Sat, 14 Jun 1997 21:58:42 -0400 (EDT)
Message-Id: <QQctzb28430.199706150158@crystal.WonderWorks.COM>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
From: Kyle Jones <kyle_jones@wonderworks.com>
To: xemacs-beta@xemacs.org
Subject: [PATCH] 20.3-b6: fix for make-tty-device crash
X-Mailer: VM 6.33 under 20.3 "Moscow" XEmacs Lucid (beta6)
X-Face: /cA45WHG7jWq>(O3&Z57Y<"WsX5ddc,4c#w0F*zrV#=M
        0@~@,s;b,aMtR5Sqs"+nU.z^CSFQ9t`z2>W,S,]:[+2^
        Nbf6v4g>!&,7R4Ot4Wg{&tm=WX7P["9%a)_da48-^tGy
        ,qz]Z,Zz\{E.,]'EO+F)@$KtF&V

Open two xterms.  Start xemacs -nw in one xterm, find out the tty
device used by the other.  Eval

(make-tty-device "/dev/ttyp0" "xterm" 32100)

Substitute the tty of the other xterm for ttyp0 above.

Switch to the other xterm and press RET.  Crash city for XEmacs.
Because Fselect_console does not check the DEVICE_SELECTED_FRAME
slot of the device struct, it can call Fselect_window on something
that is not a window.

I found this while investigating John Jones' gnuclient -nw
crash.  I don't know if this patch will fix that crash or not.
My intuition says "not."  But since I can't duplicate that
crash I don't know for sure.

Here's a patch.  Recommended for the 19.15 official patches.

Sat Jun 14 21:55:27 1997  Kyle Jones  <kyle_jones@wonderworks.com>

	* src/console.c (Fselect_console):
	  Check DEVICE_SELECTED_FRAME of console's selected
	  device for non-nil value before using it as a frame.

--- 1.2	1997/06/15 01:29:14
+++ src/console.c	1997/06/15 01:29:26
@@ -268,12 +268,23 @@
 */
        (console))
 {
+  Lisp_Object device;
+
   CHECK_LIVE_CONSOLE (console);
 
-  /* select the console's selected frame's selected window.  This will call
-     selected_frame_1(). */
-  if (!NILP (CONSOLE_SELECTED_DEVICE (XCONSOLE (console))))
-    Fselect_window (FRAME_SELECTED_WINDOW (XFRAME (DEVICE_SELECTED_FRAME (XDEVICE (CONSOLE_SELECTED_DEVICE (XCONSOLE (console)))))));
+  device = CONSOLE_SELECTED_DEVICE (XCONSOLE (console));
+  if (!NILP (device))
+    {
+      struct device *d = XDEVICE (device);
+      Lisp_Object frame = DEVICE_SELECTED_FRAME (d);
+      if (!NILP (frame))
+	{
+	  struct frame *f = XFRAME(frame);
+	  Fselect_window (FRAME_SELECTED_WINDOW (f));
+	}
+      else
+	error ("Can't select console with no frames.");
+    }
   else
     error ("Can't select a console with no devices");
   return Qnil;

