diff options
| author | Eli Zaretskii | 2015-01-31 20:48:53 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2015-01-31 20:48:53 +0200 |
| commit | a2c32b0cfc9f6d3410e2832d8ea0d4f1df576d1e (patch) | |
| tree | c2c1167bcd193c53c7293d77b5eb3210c33399ef /src/keyboard.c | |
| parent | 080b9b56c99cfdfa286fb6b8c3099626688dc8ae (diff) | |
| download | emacs-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.
Diffstat (limited to 'src/keyboard.c')
| -rw-r--r-- | src/keyboard.c | 53 |
1 files changed, 32 insertions, 21 deletions
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. |