From 96ac0c3ebce825e60595794f99e703ec8302e240 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 24 Oct 2016 21:37:20 +0300 Subject: [PATCH] Yet another fix for using pointers into buffer text * src/search.c (boyer_moore): Update pointers to buffer text after call to set_search_regs. (Bug#24358) --- src/search.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/search.c b/src/search.c index f8acd40fa08..b50e7f032d5 100644 --- a/src/search.c +++ b/src/search.c @@ -2014,13 +2014,20 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat, cursor += dirlen - i - direction; /* fix cursor */ if (i + direction == 0) { - ptrdiff_t position, start, end; + ptrdiff_t position, start, end, cursor_off; cursor -= direction; position = pos_byte + cursor - p2 + ((direction > 0) ? 1 - len_byte : 0); + /* set_search_regs might call malloc, which could + cause ralloc.c relocate buffer text. We need to + update pointers into buffer text due to that. */ + cursor_off = cursor - p2; set_search_regs (position, len_byte); + p_limit = BYTE_POS_ADDR (limit); + p2 = BYTE_POS_ADDR (pos_byte); + cursor = p2 + cursor_off; if (NILP (Vinhibit_changing_match_data)) { -- 2.39.5