Mercurial > emacs
comparison src/coding.c @ 107321:9b814b3ee348
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.
| author | Eli Zaretskii <eliz@gnu.org> |
|---|---|
| date | Tue, 02 Mar 2010 22:35:44 +0200 |
| parents | e98bd64897e0 |
| children | ebc10ed88b5c |
comparison
equal
deleted
inserted
replaced
| 107320:d2bfe26756ed | 107321:9b814b3ee348 |
|---|---|
| 1003 default: | 1003 default: |
| 1004 Vlast_code_conversion_error = intern ("Unknown error"); | 1004 Vlast_code_conversion_error = intern ("Unknown error"); |
| 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; \ |
| 1011 c = DECODE_CHAR (charset, code); \ | 1015 c = DECODE_CHAR (charset, code); \ |
| 1012 if (charset_map_loaded) \ | 1016 if (charset_map_loaded) \ |
| 2176 break; | 2180 break; |
| 2177 | 2181 |
| 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 } |
| 2185 *nbytes = src - src_base; | 2189 *nbytes = src - src_base; |
| 2186 *nchars = consumed_chars; | 2190 *nchars = consumed_chars; |
| 2523 } | 2527 } |
| 2524 } | 2528 } |
| 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) |
| 2534 goto invalid_code; | 2552 goto invalid_code; |
| 2535 if (c == -2) | 2553 if (c == -2) |
