From xemacs-m  Tue Sep 16 16:51:42 1997
Received: from mercury.Sun.COM (mercury.Sun.COM [192.9.25.1])
	by xemacs.org (8.8.5/8.8.5) with SMTP id QAA17917
	for <xemacs-beta@xemacs.org>; Tue, 16 Sep 1997 16:51:41 -0500 (CDT)
Received: from Eng.Sun.COM ([129.146.1.25]) by mercury.Sun.COM (SMI-8.6/mail.byaddr) with SMTP id OAA26506; Tue, 16 Sep 1997 14:51:15 -0700
Received: from kindra.eng.sun.com by Eng.Sun.COM (SMI-8.6/SMI-5.3)
	id OAA11508; Tue, 16 Sep 1997 14:50:58 -0700
Received: from xemacs.eng.sun.com by kindra.eng.sun.com (SMI-8.6/SMI-SVR4)
	id OAA28410; Tue, 16 Sep 1997 14:50:41 -0700
Received: by xemacs.eng.sun.com (SMI-8.6/SMI-SVR4)
	id OAA03313; Tue, 16 Sep 1997 14:50:40 -0700
Date: Tue, 16 Sep 1997 14:50:40 -0700
Message-Id: <199709162150.OAA03313@xemacs.eng.sun.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
From: Martin Buchholz <mrb@Eng.Sun.COM>
To: Hrvoje Niksic <hniksic@srce.hr>, Dan Rich <drich@cisco.com>
Cc: XEmacs Developers <xemacs-beta@xemacs.org>
Subject: Re: gnuclient works? (and a gnuclient induced core dump!)
In-Reply-To: <kig202par3d.fsf@jagor.srce.hr>
References: <199709161820.LAA00367@sandman>
	<kig202par3d.fsf@jagor.srce.hr>
X-Mailer: VM 6.33 under 20.3 "Vienna" XEmacs  Lucid (beta14)
Reply-To: Martin Buchholz <mrb@Eng.Sun.COM>

>>>>> "Hrvoje" == Hrvoje Niksic <hniksic@srce.hr> writes:

Hrvoje> Dan Rich <drich@cisco.com> writes:
>> I was running into a similar problem yesterday though, I couldn't get 
>> gnuclient to connect.  I was using 'gnuclient -nw' from a telnet window
>> on my boat anchor^h^h^h^h^h^h^h^h^h^h^h PC, and it just sat there without
>> ever updating my screen.  When I tried it now (from an xterm on the same
>> system as my XEmacs process), it dumped core!
>> 
>> Here's the lisp backtrace:
>> Lisp backtrace follows:

Hrvoje> The C backtrace doesn't seem connected to gnuclient:

>> #4  0x8cafc in assert_failed (file=0x2563c0 "insdel.c", line=369, 
>> expr=0x2563e8 "ptr == end") at emacs.c:2209
>> #5  0x131dec in bytecount_to_charcount (ptr=0x15fc508 "[2~", len=3)
>> at insdel.c:369
>> #6  0x4b1e4 in make_string (contents=0x15fc503 "\eO\200", length=3)
>> at alloc.c:2124
>> #7  0x4b2e8 in build_string (str=0x15fc503 "\eO\200") at alloc.c:2149

Hrvoje> Why would this `build_string' cause a crash?  Memory corruption?  Mule 
Hrvoje> bug?

build_string requires that the string passed to it as argument is
encoded using the internal Mule encoding.  When obtaining strings from 
outside of XEmacs, this is only safe if the argument string is
guaranteed to be 7-bit ASCII.

So I bet that the terminfo entry for the terminal has non-ASCII
(i.e. high bit on) characters.

term_get_fkeys_1 has not been mule-ized.  It needs to use
build_ext_string instead of build_string.

Hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

OK. Dan, could you try this completely untested patch?

--- src/redisplay-tty.c.old
+++ src/redisplay-tty.c
@@ -1425,7 +1425,7 @@
       char *sequence = tgetstr (keys[i].cap, address);
       if (sequence)
 	Fdefine_key (function_key_map,
-		     build_string (sequence),
+		     build_ext_string (sequence, FORMAT_BINARY),
 		     vector1 (intern (keys[i].name)));
     }
 
@@ -1441,13 +1441,13 @@
 
     if (k_semi)
       {
-	Fdefine_key (function_key_map, build_string (k_semi),
+	Fdefine_key (function_key_map, build_ext_string (k_semi, FORMAT_BINARY),
 		     vector1 (intern ("f10")));
 	k0_name = "f0";
       }
 
     if (k0)
-      Fdefine_key (function_key_map, build_string (k0),
+      Fdefine_key (function_key_map, build_ext_string (k0, FORMAT_BINARY),
 		   vector1 (intern (k0_name)));
   }
 
@@ -1471,7 +1471,7 @@
 	    {
 	      sprintf (fkey, "f%d", i);
 	      Fdefine_key (function_key_map,
-			   build_string (sequence),
+			   build_ext_string (sequence, FORMAT_BINARY),
 			   vector1 (intern (fkey)));
 	    }
 	}
@@ -1488,7 +1488,7 @@
 	  char *sequence = tgetstr (cap2, address);			\
 	  if (sequence)							\
 	    Fdefine_key (function_key_map,				\
-			 build_string (sequence),			\
+			 build_ext_string (sequence, FORMAT_BINARY),	\
 			 vector1 (intern (sym)));			\
 	}
 

