diff options
| author | Eli Zaretskii | 2010-03-02 22:35:44 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2010-03-02 22:35:44 +0200 |
| commit | 75f80e63caa66ef6127738a9cfc875e876a9b5ff (patch) | |
| tree | d30d56138399747b76d700533051160df3881d03 /src | |
| parent | 9cf3544e3bc88406c361bff9f7a7592d26feebe5 (diff) | |
| download | emacs-75f80e63caa66ef6127738a9cfc875e876a9b5ff.tar.gz emacs-75f80e63caa66ef6127738a9cfc875e876a9b5ff.zip | |
Fix bug in decoding emacs-mule encoding.
coding.c (decode_coding_emacs_mule): Fixup pointers to buffer
text that could be relocated inside the call to emacs_mule_char.
(emacs_mule_char): Use CODING_DECODE_CHAR instead of DECODE_CHAR.
(CODING_DECODE_CHAR): Add a comment describing its purpose.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/coding.c | 20 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index aec692b39ed..761beb2be54 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2010-03-02 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * coding.c (decode_coding_emacs_mule): Fixup pointers to buffer | ||
| 4 | text that could be relocated inside the call to emacs_mule_char. | ||
| 5 | (emacs_mule_char): Use CODING_DECODE_CHAR instead of DECODE_CHAR. | ||
| 6 | (CODING_DECODE_CHAR): Add a comment describing its purpose. | ||
| 7 | |||
| 1 | 2010-03-02 Kenichi Handa <handa@m17n.org> | 8 | 2010-03-02 Kenichi Handa <handa@m17n.org> |
| 2 | 9 | ||
| 3 | * character.c (parse_str_as_multibyte): Fix handling of the | 10 | * character.c (parse_str_as_multibyte): Fix handling of the |
diff --git a/src/coding.c b/src/coding.c index 2144fe5fcd4..27931c123d2 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -1005,6 +1005,10 @@ record_conversion_result (struct coding_system *coding, | |||
| 1005 | } | 1005 | } |
| 1006 | } | 1006 | } |
| 1007 | 1007 | ||
| 1008 | /* This wrapper macro is used to preserve validity of pointers into | ||
| 1009 | buffer text across calls to decode_char, which could cause | ||
| 1010 | relocation of buffers if it loads a charset map, because loading a | ||
| 1011 | charset map allocates large structures. */ | ||
| 1008 | #define CODING_DECODE_CHAR(coding, src, src_base, src_end, charset, code, c) \ | 1012 | #define CODING_DECODE_CHAR(coding, src, src_base, src_end, charset, code, c) \ |
| 1009 | do { \ | 1013 | do { \ |
| 1010 | charset_map_loaded = 0; \ | 1014 | charset_map_loaded = 0; \ |
| @@ -2178,7 +2182,7 @@ emacs_mule_char (coding, src, nbytes, nchars, id, cmp_status) | |||
| 2178 | default: | 2182 | default: |
| 2179 | abort (); | 2183 | abort (); |
| 2180 | } | 2184 | } |
| 2181 | c = DECODE_CHAR (charset, code); | 2185 | CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, code, c); |
| 2182 | if (c < 0) | 2186 | if (c < 0) |
| 2183 | goto invalid_code; | 2187 | goto invalid_code; |
| 2184 | } | 2188 | } |
| @@ -2525,9 +2529,23 @@ decode_coding_emacs_mule (coding) | |||
| 2525 | else | 2529 | else |
| 2526 | { | 2530 | { |
| 2527 | int nchars, nbytes; | 2531 | int nchars, nbytes; |
| 2532 | /* emacs_mule_char can load a charset map from a file, which | ||
| 2533 | allocates a large structure and might cause buffer text | ||
| 2534 | to be relocated as result. Thus, we need to remember the | ||
| 2535 | original pointer to buffer text, and fixup all related | ||
| 2536 | pointers after the call. */ | ||
| 2537 | const unsigned char *orig = coding->source; | ||
| 2538 | EMACS_INT offset; | ||
| 2528 | 2539 | ||
| 2529 | c = emacs_mule_char (coding, src_base, &nbytes, &nchars, &id, | 2540 | c = emacs_mule_char (coding, src_base, &nbytes, &nchars, &id, |
| 2530 | cmp_status); | 2541 | cmp_status); |
| 2542 | offset = coding->source - orig; | ||
| 2543 | if (offset) | ||
| 2544 | { | ||
| 2545 | src += offset; | ||
| 2546 | src_base += offset; | ||
| 2547 | src_end += offset; | ||
| 2548 | } | ||
| 2531 | if (c < 0) | 2549 | if (c < 0) |
| 2532 | { | 2550 | { |
| 2533 | if (c == -1) | 2551 | if (c == -1) |