From: Eli Zaretskii Date: Sat, 31 Jan 2015 18:48:53 +0000 (+0200) Subject: Avoid aborts when keyboard-coding-system is raw-text (Bug#19532) X-Git-Tag: emacs-25.0.90~2572^2 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a2c32b0cfc9f6d3410e2832d8ea0d4f1df576d1e;p=emacs.git 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. --- diff --git a/src/ChangeLog b/src/ChangeLog index 6208738cc57..9e564ea6414 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2015-01-31 Eli Zaretskii + + * 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 * Makefile.in (gl-stamp): Generate globals.h through the use of diff --git a/src/coding.c b/src/coding.c index a7128ee3e73..1a0e1279648 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 d49d786e6dd..c73a9cc3263 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 7718f8efa7b..1176d701f2a 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.