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.
This commit is contained in:
parent
080b9b56c9
commit
a2c32b0cfc
4 changed files with 51 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue