Subject: bug#638: 23.0.60; read-char evaluates to unexpected non-character value

From: Lawrence Mitchell <[email-masked]>
Date: Fri, 01 Aug 2008 13:49:35 +0100

Markus Triska wrote:
> When I do:

>    $ emacs -Q --eval "(insert (format \"%s\" (read-char nil nil 0.1))))"

> The content of *scratch* is:

>    7340161

This is due to the following change:

2008-03-05  Kenichi Handa  <[email-masked]>

	* lread.c (Fread_char): Resolve modifiers.
	(Fread_char_exclusive): Likewise.

It unconditionally resolves modifiers even if read_filtered_event
returns nil.  The following patch fixes things, I think.

2008-08-01  Lawrence Mitchell  <[email-masked]>

	* lread.c (Fread_char, Fread_char_exclusive): If no character
	event is read before timeout is reached, return nil, rather than
	converting to a number.

diff --git a/src/lread.c b/src/lread.c
index f36162b..97b22d5 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -796,6 +796,8 @@ floating-point value.  */)
   if (! NILP (prompt))
     message_with_string ("%s", prompt, 0);
   val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds);
+  if ( NILP (val) )
+    return Qnil;
   c = XINT (val);
   return make_number (char_resolve_modifier_mask (c));
 }
@@ -841,6 +843,8 @@ floating-point value.  */)
   if (! NILP (prompt))
     message_with_string ("%s", prompt, 0);
   val = read_filtered_event (1, 1, 0, ! NILP (inherit_input_method), seconds);
+  if ( NILP (val) )
+    return Qnil;
   c = XINT (val);
   return make_number (char_resolve_modifier_mask (c));
 }
-- 
1.5.6.GIT

-- 
Lawrence Mitchell <[email-masked]>