aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c20
1 files changed, 19 insertions, 1 deletions
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)