summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2015-01-31 20:48:53 +0200
committerEli Zaretskii <eliz@gnu.org>2015-01-31 20:48:53 +0200
commita2c32b0cfc9f6d3410e2832d8ea0d4f1df576d1e (patch)
treec2c1167bcd193c53c7293d77b5eb3210c33399ef
parent080b9b56c99cfdfa286fb6b8c3099626688dc8ae (diff)
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 6208738cc5..9e564ea641 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -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
diff --git a/src/coding.c b/src/coding.c
index a7128ee3e7..1a0e127964 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 d49d786e6d..c73a9cc326 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 7718f8efa7..1176d701f2 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.