diff options
| author | Paul Eggert | 2016-10-25 12:50:31 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-10-25 12:50:31 -0700 |
| commit | f8eecb1c6c8a3646d65112843c7f813fe639d57f (patch) | |
| tree | a8973cca6836e72ed2d0e36ba5242c02ff220fdf /src | |
| parent | 43645b4dc4eb4611127dc8931a723e872824ecaf (diff) | |
| parent | 96ac0c3ebce825e60595794f99e703ec8302e240 (diff) | |
| download | emacs-f8eecb1c6c8a3646d65112843c7f813fe639d57f.tar.gz emacs-f8eecb1c6c8a3646d65112843c7f813fe639d57f.zip | |
Merge from origin/emacs-25
96ac0c3 Yet another fix for using pointers into buffer text
1047496 Another fix for using pointer to buffer text
3121992 Fix Bug#24478
Diffstat (limited to 'src')
| -rw-r--r-- | src/search.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/search.c b/src/search.c index 127a57ab1db..92bfa88eb82 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -2007,13 +2007,20 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat, | |||
| 2007 | cursor += dirlen - i - direction; /* fix cursor */ | 2007 | cursor += dirlen - i - direction; /* fix cursor */ |
| 2008 | if (i + direction == 0) | 2008 | if (i + direction == 0) |
| 2009 | { | 2009 | { |
| 2010 | ptrdiff_t position, start, end; | 2010 | ptrdiff_t position, start, end, cursor_off; |
| 2011 | 2011 | ||
| 2012 | cursor -= direction; | 2012 | cursor -= direction; |
| 2013 | 2013 | ||
| 2014 | position = pos_byte + cursor - p2 + ((direction > 0) | 2014 | position = pos_byte + cursor - p2 + ((direction > 0) |
| 2015 | ? 1 - len_byte : 0); | 2015 | ? 1 - len_byte : 0); |
| 2016 | /* set_search_regs might call malloc, which could | ||
| 2017 | cause ralloc.c relocate buffer text. We need to | ||
| 2018 | update pointers into buffer text due to that. */ | ||
| 2019 | cursor_off = cursor - p2; | ||
| 2016 | set_search_regs (position, len_byte); | 2020 | set_search_regs (position, len_byte); |
| 2021 | p_limit = BYTE_POS_ADDR (limit); | ||
| 2022 | p2 = BYTE_POS_ADDR (pos_byte); | ||
| 2023 | cursor = p2 + cursor_off; | ||
| 2017 | 2024 | ||
| 2018 | if (NILP (Vinhibit_changing_match_data)) | 2025 | if (NILP (Vinhibit_changing_match_data)) |
| 2019 | { | 2026 | { |
| @@ -2633,6 +2640,7 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2633 | const unsigned char *add_stuff = NULL; | 2640 | const unsigned char *add_stuff = NULL; |
| 2634 | ptrdiff_t add_len = 0; | 2641 | ptrdiff_t add_len = 0; |
| 2635 | ptrdiff_t idx = -1; | 2642 | ptrdiff_t idx = -1; |
| 2643 | ptrdiff_t begbyte; | ||
| 2636 | 2644 | ||
| 2637 | if (str_multibyte) | 2645 | if (str_multibyte) |
| 2638 | { | 2646 | { |
| @@ -2695,11 +2703,10 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2695 | set up ADD_STUFF and ADD_LEN to point to it. */ | 2703 | set up ADD_STUFF and ADD_LEN to point to it. */ |
| 2696 | if (idx >= 0) | 2704 | if (idx >= 0) |
| 2697 | { | 2705 | { |
| 2698 | ptrdiff_t begbyte = CHAR_TO_BYTE (search_regs.start[idx]); | 2706 | begbyte = CHAR_TO_BYTE (search_regs.start[idx]); |
| 2699 | add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte; | 2707 | add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte; |
| 2700 | if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx]) | 2708 | if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx]) |
| 2701 | move_gap_both (search_regs.start[idx], begbyte); | 2709 | move_gap_both (search_regs.start[idx], begbyte); |
| 2702 | add_stuff = BYTE_POS_ADDR (begbyte); | ||
| 2703 | } | 2710 | } |
| 2704 | 2711 | ||
| 2705 | /* Now the stuff we want to add to SUBSTED | 2712 | /* Now the stuff we want to add to SUBSTED |
| @@ -2712,6 +2719,11 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2712 | add_len - (substed_alloc_size - substed_len), | 2719 | add_len - (substed_alloc_size - substed_len), |
| 2713 | STRING_BYTES_BOUND, 1); | 2720 | STRING_BYTES_BOUND, 1); |
| 2714 | 2721 | ||
| 2722 | /* We compute this after the call to xpalloc, because that | ||
| 2723 | could cause buffer text be relocated when ralloc.c is used. */ | ||
| 2724 | if (idx >= 0) | ||
| 2725 | add_stuff = BYTE_POS_ADDR (begbyte); | ||
| 2726 | |||
| 2715 | /* Now add to the end of SUBSTED. */ | 2727 | /* Now add to the end of SUBSTED. */ |
| 2716 | if (add_stuff) | 2728 | if (add_stuff) |
| 2717 | { | 2729 | { |