aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2015-01-31 20:48:53 +0200
committerEli Zaretskii2015-01-31 20:48:53 +0200
commita2c32b0cfc9f6d3410e2832d8ea0d4f1df576d1e (patch)
treec2c1167bcd193c53c7293d77b5eb3210c33399ef
parent080b9b56c99cfdfa286fb6b8c3099626688dc8ae (diff)
downloademacs-a2c32b0cfc9f6d3410e2832d8ea0d4f1df576d1e.tar.gz
emacs-a2c32b0cfc9f6d3410e2832d8ea0d4f1df576d1e.zip
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.
-rw-r--r--src/ChangeLog9
-rw-r--r--src/coding.c9
-rw-r--r--src/coding.h1
-rw-r--r--src/keyboard.c53
4 files changed, 51 insertions, 21 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 6208738cc57..9e564ea6414 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
12015-01-31 Eli Zaretskii <eliz@gnu.org>
2
3 * coding.c (raw_text_coding_system_p): New function.
4
5 * keyboard.c (read_decoded_event_from_main_queue): Use it when the
6 keyboard coding-system is 'raw-text'. (Bug#19532)
7
8 * coding.h (raw_text_coding_system_p): Add prototype.
9
12015-01-31 Andreas Schwab <schwab@linux-m68k.org> 102015-01-31 Andreas Schwab <schwab@linux-m68k.org>
2 11
3 * Makefile.in (gl-stamp): Generate globals.h through the use of 12 * 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)
5979 : AREF (raw_text_eol_type, 2)); 5979 : AREF (raw_text_eol_type, 2));
5980} 5980}
5981 5981
5982/* Return true if CODING corresponds to raw-text coding-system. */
5983
5984bool
5985raw_text_coding_system_p (struct coding_system *coding)
5986{
5987 return (coding->decoder == decode_coding_raw_text
5988 && coding->encoder == encode_coding_raw_text) ? true : false;
5989}
5990
5982 5991
5983/* If CODING_SYSTEM doesn't specify end-of-line format, return one of 5992/* If CODING_SYSTEM doesn't specify end-of-line format, return one of
5984 the subsidiary that has the same eol-spec as PARENT (if it is not 5993 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,
705extern Lisp_Object encode_file_name (Lisp_Object); 705extern Lisp_Object encode_file_name (Lisp_Object);
706extern Lisp_Object decode_file_name (Lisp_Object); 706extern Lisp_Object decode_file_name (Lisp_Object);
707extern Lisp_Object raw_text_coding_system (Lisp_Object); 707extern Lisp_Object raw_text_coding_system (Lisp_Object);
708extern bool raw_text_coding_system_p (struct coding_system *);
708extern Lisp_Object coding_inherit_eol_type (Lisp_Object, Lisp_Object); 709extern Lisp_Object coding_inherit_eol_type (Lisp_Object, Lisp_Object);
709extern Lisp_Object complement_process_encoding_system (Lisp_Object); 710extern Lisp_Object complement_process_encoding_system (Lisp_Object);
710 711
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,
2288 { /* An encoded byte sequence, let's try to decode it. */ 2288 { /* An encoded byte sequence, let's try to decode it. */
2289 struct coding_system *coding 2289 struct coding_system *coding
2290 = TERMINAL_KEYBOARD_CODING (terminal); 2290 = TERMINAL_KEYBOARD_CODING (terminal);
2291 unsigned char src[MAX_ENCODED_BYTES]; 2291
2292 unsigned char dest[MAX_ENCODED_BYTES * MAX_MULTIBYTE_LENGTH]; 2292 if (raw_text_coding_system_p (coding))
2293 int i; 2293 {
2294 for (i = 0; i < n; i++) 2294 int i;
2295 src[i] = XINT (events[i]); 2295 if (meta_key != 2)
2296 if (meta_key != 2) 2296 for (i = 0; i < n; i++)
2297 for (i = 0; i < n; i++) 2297 events[i] = make_number (XINT (events[i]) & ~0x80);
2298 src[i] &= ~0x80;
2299 coding->destination = dest;
2300 coding->dst_bytes = sizeof dest;
2301 decode_coding_c_string (coding, src, n, Qnil);
2302 eassert (coding->produced_char <= n);
2303 if (coding->produced_char == 0)
2304 { /* The encoded sequence is incomplete. */
2305 if (n < MAX_ENCODED_BYTES) /* Avoid buffer overflow. */
2306 continue; /* Read on! */
2307 } 2298 }
2308 else 2299 else
2309 { 2300 {
2310 const unsigned char *p = coding->destination; 2301 unsigned char src[MAX_ENCODED_BYTES];
2311 eassert (coding->carryover_bytes == 0); 2302 unsigned char dest[MAX_ENCODED_BYTES * MAX_MULTIBYTE_LENGTH];
2312 n = 0; 2303 int i;
2313 while (n < coding->produced_char) 2304 for (i = 0; i < n; i++)
2314 events[n++] = make_number (STRING_CHAR_ADVANCE (p)); 2305 src[i] = XINT (events[i]);
2306 if (meta_key != 2)
2307 for (i = 0; i < n; i++)
2308 src[i] &= ~0x80;
2309 coding->destination = dest;
2310 coding->dst_bytes = sizeof dest;
2311 decode_coding_c_string (coding, src, n, Qnil);
2312 eassert (coding->produced_char <= n);
2313 if (coding->produced_char == 0)
2314 { /* The encoded sequence is incomplete. */
2315 if (n < MAX_ENCODED_BYTES) /* Avoid buffer overflow. */
2316 continue; /* Read on! */
2317 }
2318 else
2319 {
2320 const unsigned char *p = coding->destination;
2321 eassert (coding->carryover_bytes == 0);
2322 n = 0;
2323 while (n < coding->produced_char)
2324 events[n++] = make_number (STRING_CHAR_ADVANCE (p));
2325 }
2315 } 2326 }
2316 } 2327 }
2317 /* Now `events' should hold decoded events. 2328 /* Now `events' should hold decoded events.