]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid aborts when keyboard-coding-system is raw-text (Bug#19532)
authorEli Zaretskii <eliz@gnu.org>
Sat, 31 Jan 2015 18:48:53 +0000 (20:48 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 31 Jan 2015 18:48:53 +0000 (20:48 +0200)
 src/coding.c (raw_text_coding_system_p): New function.
 src/keyboard.c (read_decoded_event_from_main_queue): Use it when the
 keyboard coding-system is 'raw-text'.
 src/coding.h (raw_text_coding_system_p): Add prototype.

src/ChangeLog
src/coding.c
src/coding.h
src/keyboard.c

index 6208738cc57c76a1bf9197f9d29a89d7b96ce936..9e564ea6414d7f4a3d8a28bad2256e6448f5fed0 100644 (file)
@@ -1,3 +1,12 @@
+2015-01-31  Eli Zaretskii  <eliz@gnu.org>
+
+       * coding.c (raw_text_coding_system_p): New function.
+
+       * keyboard.c (read_decoded_event_from_main_queue): Use it when the
+       keyboard coding-system is 'raw-text'.  (Bug#19532)
+
+       * coding.h (raw_text_coding_system_p): Add prototype.
+
 2015-01-31  Andreas Schwab  <schwab@linux-m68k.org>
 
        * Makefile.in (gl-stamp): Generate globals.h through the use of
index a7128ee3e7391bda96ed9db67033656be3119555..1a0e12796486c77f6b88666eac69f527bd0a3ea6 100644 (file)
@@ -5979,6 +5979,15 @@ raw_text_coding_system (Lisp_Object coding_system)
          : AREF (raw_text_eol_type, 2));
 }
 
+/* Return true if CODING corresponds to raw-text coding-system.  */
+
+bool
+raw_text_coding_system_p (struct coding_system *coding)
+{
+  return (coding->decoder == decode_coding_raw_text
+         && coding->encoder == encode_coding_raw_text) ? true : false;
+}
+
 
 /* If CODING_SYSTEM doesn't specify end-of-line format, return one of
    the subsidiary that has the same eol-spec as PARENT (if it is not
index d49d786e6dd76ae264f502e9df763f198edb8461..c73a9cc32636dc934a954b0344d2aff4251ee018 100644 (file)
@@ -705,6 +705,7 @@ extern Lisp_Object code_convert_string_norecord (Lisp_Object, Lisp_Object,
 extern Lisp_Object encode_file_name (Lisp_Object);
 extern Lisp_Object decode_file_name (Lisp_Object);
 extern Lisp_Object raw_text_coding_system (Lisp_Object);
+extern bool raw_text_coding_system_p (struct coding_system *);
 extern Lisp_Object coding_inherit_eol_type (Lisp_Object, Lisp_Object);
 extern Lisp_Object complement_process_encoding_system (Lisp_Object);
 
index 7718f8efa7b08bdfd44aeb1797b543f07ccf441f..1176d701f2a16032481d20b0a1c50d6de37c3cd0 100644 (file)
@@ -2288,30 +2288,41 @@ read_decoded_event_from_main_queue (struct timespec *end_time,
            { /* An encoded byte sequence, let's try to decode it.  */
              struct coding_system *coding
                = TERMINAL_KEYBOARD_CODING (terminal);
-             unsigned char src[MAX_ENCODED_BYTES];
-             unsigned char dest[MAX_ENCODED_BYTES * MAX_MULTIBYTE_LENGTH];
-             int i;
-             for (i = 0; i < n; i++)
-               src[i] = XINT (events[i]);
-             if (meta_key != 2)
-               for (i = 0; i < n; i++)
-                 src[i] &= ~0x80;
-             coding->destination = dest;
-             coding->dst_bytes = sizeof dest;
-             decode_coding_c_string (coding, src, n, Qnil);
-             eassert (coding->produced_char <= n);
-             if (coding->produced_char == 0)
-               { /* The encoded sequence is incomplete.  */
-                 if (n < MAX_ENCODED_BYTES) /* Avoid buffer overflow.  */
-                   continue;                /* Read on!  */
+
+             if (raw_text_coding_system_p (coding))
+               {
+                 int i;
+                 if (meta_key != 2)
+                   for (i = 0; i < n; i++)
+                     events[i] = make_number (XINT (events[i]) & ~0x80);
                }
              else
                {
-                 const unsigned char *p = coding->destination;
-                 eassert (coding->carryover_bytes == 0);
-                 n = 0;
-                 while (n < coding->produced_char)
-                   events[n++] = make_number (STRING_CHAR_ADVANCE (p));
+                 unsigned char src[MAX_ENCODED_BYTES];
+                 unsigned char dest[MAX_ENCODED_BYTES * MAX_MULTIBYTE_LENGTH];
+                 int i;
+                 for (i = 0; i < n; i++)
+                   src[i] = XINT (events[i]);
+                 if (meta_key != 2)
+                   for (i = 0; i < n; i++)
+                     src[i] &= ~0x80;
+                 coding->destination = dest;
+                 coding->dst_bytes = sizeof dest;
+                 decode_coding_c_string (coding, src, n, Qnil);
+                 eassert (coding->produced_char <= n);
+                 if (coding->produced_char == 0)
+                   { /* The encoded sequence is incomplete.  */
+                     if (n < MAX_ENCODED_BYTES) /* Avoid buffer overflow.  */
+                       continue;                    /* Read on!  */
+                   }
+                 else
+                   {
+                     const unsigned char *p = coding->destination;
+                     eassert (coding->carryover_bytes == 0);
+                     n = 0;
+                     while (n < coding->produced_char)
+                       events[n++] = make_number (STRING_CHAR_ADVANCE (p));
+                   }
                }
            }
          /* Now `events' should hold decoded events.