emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master a2c32b0: Avoid aborts when keyboard-coding-system i


From: Eli Zaretskii
Subject: [Emacs-diffs] master a2c32b0: Avoid aborts when keyboard-coding-system is raw-text (Bug#19532)
Date: Sat, 31 Jan 2015 18:50:52 +0000

branch: master
commit a2c32b0cfc9f6d3410e2832d8ea0d4f1df576d1e
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Avoid aborts when keyboard-coding-system is raw-text  (Bug#19532)
    
     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  |    9 +++++++++
 src/coding.c   |    9 +++++++++
 src/coding.h   |    1 +
 src/keyboard.c |   53 ++++++++++++++++++++++++++++++++---------------------
 4 files changed, 51 insertions(+), 21 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 6208738..9e564ea 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
+2015-01-31  Eli Zaretskii  <address@hidden>
+
+       * 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  <address@hidden>
 
        * Makefile.in (gl-stamp): Generate globals.h through the use of
diff --git a/src/coding.c b/src/coding.c
index a7128ee..1a0e1279 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -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
diff --git a/src/coding.h b/src/coding.h
index d49d786..c73a9cc 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -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);
 
diff --git a/src/keyboard.c b/src/keyboard.c
index 7718f8e..1176d70 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]