aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c5
-rw-r--r--src/buffer.h4
-rw-r--r--src/intervals.c36
-rw-r--r--src/marker.c4
4 files changed, 18 insertions, 31 deletions
diff --git a/src/buffer.c b/src/buffer.c
index ab477481912..3b5078a175b 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2264,7 +2264,7 @@ validate_region (register Lisp_Object *b, register Lisp_Object *e)
2264/* Advance BYTE_POS up to a character boundary 2264/* Advance BYTE_POS up to a character boundary
2265 and return the adjusted position. */ 2265 and return the adjusted position. */
2266 2266
2267static ptrdiff_t 2267ptrdiff_t
2268advance_to_char_boundary (ptrdiff_t byte_pos) 2268advance_to_char_boundary (ptrdiff_t byte_pos)
2269{ 2269{
2270 int c; 2270 int c;
@@ -2702,6 +2702,9 @@ current buffer is cleared. */)
2702 2702
2703 /* Do this last, so it can calculate the new correspondences 2703 /* Do this last, so it can calculate the new correspondences
2704 between chars and bytes. */ 2704 between chars and bytes. */
2705 /* FIXME: Is it worth the trouble, really? Couldn't we just throw
2706 away all the text-properties instead of trying to guess how
2707 to adjust them? AFAICT the result is not reliable anyway. */
2705 set_intervals_multibyte (1); 2708 set_intervals_multibyte (1);
2706 } 2709 }
2707 2710
diff --git a/src/buffer.h b/src/buffer.h
index f42c3e97b97..2080a6f40b7 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -327,6 +327,10 @@ extern void enlarge_buffer_text (struct buffer *, ptrdiff_t);
327#define BYTE_TO_CHAR(bytepos) \ 327#define BYTE_TO_CHAR(bytepos) \
328 (buf_bytepos_to_charpos (current_buffer, bytepos)) 328 (buf_bytepos_to_charpos (current_buffer, bytepos))
329 329
330/* For those very rare cases where you may have a "random" pointer into
331 the middle of a multibyte char, this moves to the next boundary. */
332extern ptrdiff_t advance_to_char_boundary (ptrdiff_t byte_pos);
333
330/* Convert PTR, the address of a byte in the buffer, into a byte position. */ 334/* Convert PTR, the address of a byte in the buffer, into a byte position. */
331 335
332#define PTR_BYTE_POS(ptr) \ 336#define PTR_BYTE_POS(ptr) \
diff --git a/src/intervals.c b/src/intervals.c
index 8f39c45762f..34829ab050d 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -2335,22 +2335,10 @@ set_intervals_multibyte_1 (INTERVAL i, bool multi_flag,
2335 if (multi_flag) 2335 if (multi_flag)
2336 { 2336 {
2337 ptrdiff_t temp; 2337 ptrdiff_t temp;
2338 left_end_byte = start_byte + LEFT_TOTAL_LENGTH (i); 2338 left_end_byte
2339 = advance_to_char_boundary (start_byte + LEFT_TOTAL_LENGTH (i));
2339 left_end = BYTE_TO_CHAR (left_end_byte); 2340 left_end = BYTE_TO_CHAR (left_end_byte);
2340 2341 eassert (CHAR_TO_BYTE (left_end) == left_end_byte);
2341 temp = CHAR_TO_BYTE (left_end);
2342
2343 /* If LEFT_END_BYTE is in the middle of a character,
2344 adjust it and LEFT_END to a char boundary. */
2345 if (left_end_byte > temp)
2346 {
2347 left_end_byte = temp;
2348 }
2349 if (left_end_byte < temp)
2350 {
2351 left_end--;
2352 left_end_byte = CHAR_TO_BYTE (left_end);
2353 }
2354 } 2342 }
2355 else 2343 else
2356 { 2344 {
@@ -2369,22 +2357,10 @@ set_intervals_multibyte_1 (INTERVAL i, bool multi_flag,
2369 { 2357 {
2370 ptrdiff_t temp; 2358 ptrdiff_t temp;
2371 2359
2372 right_start_byte = end_byte - RIGHT_TOTAL_LENGTH (i); 2360 right_start_byte
2361 = advance_to_char_boundary (end_byte - RIGHT_TOTAL_LENGTH (i));
2373 right_start = BYTE_TO_CHAR (right_start_byte); 2362 right_start = BYTE_TO_CHAR (right_start_byte);
2374 2363 eassert (CHAR_TO_BYTE (right_start) == right_start_byte);
2375 /* If RIGHT_START_BYTE is in the middle of a character,
2376 adjust it and RIGHT_START to a char boundary. */
2377 temp = CHAR_TO_BYTE (right_start);
2378
2379 if (right_start_byte < temp)
2380 {
2381 right_start_byte = temp;
2382 }
2383 if (right_start_byte > temp)
2384 {
2385 right_start++;
2386 right_start_byte = CHAR_TO_BYTE (right_start);
2387 }
2388 } 2364 }
2389 else 2365 else
2390 { 2366 {
diff --git a/src/marker.c b/src/marker.c
index b58051a8c2b..0b2e1bf5c6b 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -332,6 +332,10 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
332 if (best_above == best_above_byte) 332 if (best_above == best_above_byte)
333 return bytepos; 333 return bytepos;
334 334
335 /* Check bytepos is not in the middle of a character. */
336 eassert (bytepos >= BUF_Z_BYTE (b)
337 || CHAR_HEAD_P (BUF_FETCH_BYTE (b, bytepos)));
338
335 best_below = BEG; 339 best_below = BEG;
336 best_below_byte = BEG_BYTE; 340 best_below_byte = BEG_BYTE;
337 341