diff options
| author | Noam Postavsky | 2016-10-24 21:22:07 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2016-10-25 20:15:33 -0400 |
| commit | 43986d16fb6ad78a627250e14570ea70bdb1f23a (patch) | |
| tree | cc62d12e7640e43fe98e7513b6c69b7953d404d7 /src | |
| parent | fee4cef7d720e98922858e19b3161358041ec141 (diff) | |
| download | emacs-43986d16fb6ad78a627250e14570ea70bdb1f23a.tar.gz emacs-43986d16fb6ad78a627250e14570ea70bdb1f23a.zip | |
Inhibit buffer relocation during regex searches
* src/search.c (looking_at_1, fast_looking_at, search_buffer): Prevent
relocation of buffer contents during calls to re_search_2. This ensures
the pointers into buffer text won't be invalidated by
r_alloc_sbrk (called from malloc with configurations where
REL_ALLOC=yes).
Diffstat (limited to 'src')
| -rw-r--r-- | src/search.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/search.c b/src/search.c index fa5ac44de9d..15504be042b 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -308,12 +308,20 @@ looking_at_1 (Lisp_Object string, bool posix) | |||
| 308 | 308 | ||
| 309 | re_match_object = Qnil; | 309 | re_match_object = Qnil; |
| 310 | 310 | ||
| 311 | #ifdef REL_ALLOC | ||
| 312 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 313 | searching it. */ | ||
| 314 | r_alloc_inhibit_buffer_relocation (1); | ||
| 315 | #endif | ||
| 311 | i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2, | 316 | i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2, |
| 312 | PT_BYTE - BEGV_BYTE, | 317 | PT_BYTE - BEGV_BYTE, |
| 313 | (NILP (Vinhibit_changing_match_data) | 318 | (NILP (Vinhibit_changing_match_data) |
| 314 | ? &search_regs : NULL), | 319 | ? &search_regs : NULL), |
| 315 | ZV_BYTE - BEGV_BYTE); | 320 | ZV_BYTE - BEGV_BYTE); |
| 316 | immediate_quit = 0; | 321 | immediate_quit = 0; |
| 322 | #ifdef REL_ALLOC | ||
| 323 | r_alloc_inhibit_buffer_relocation (0); | ||
| 324 | #endif | ||
| 317 | 325 | ||
| 318 | if (i == -2) | 326 | if (i == -2) |
| 319 | matcher_overflow (); | 327 | matcher_overflow (); |
| @@ -561,8 +569,16 @@ fast_looking_at (Lisp_Object regexp, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 561 | 569 | ||
| 562 | buf = compile_pattern (regexp, 0, Qnil, 0, multibyte); | 570 | buf = compile_pattern (regexp, 0, Qnil, 0, multibyte); |
| 563 | immediate_quit = 1; | 571 | immediate_quit = 1; |
| 572 | #ifdef REL_ALLOC | ||
| 573 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 574 | searching it. */ | ||
| 575 | r_alloc_inhibit_buffer_relocation (1); | ||
| 576 | #endif | ||
| 564 | len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2, | 577 | len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2, |
| 565 | pos_byte, NULL, limit_byte); | 578 | pos_byte, NULL, limit_byte); |
| 579 | #ifdef REL_ALLOC | ||
| 580 | r_alloc_inhibit_buffer_relocation (0); | ||
| 581 | #endif | ||
| 566 | immediate_quit = 0; | 582 | immediate_quit = 0; |
| 567 | 583 | ||
| 568 | return len; | 584 | return len; |
| @@ -1213,6 +1229,12 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1213 | } | 1229 | } |
| 1214 | re_match_object = Qnil; | 1230 | re_match_object = Qnil; |
| 1215 | 1231 | ||
| 1232 | #ifdef REL_ALLOC | ||
| 1233 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 1234 | searching it. */ | ||
| 1235 | r_alloc_inhibit_buffer_relocation (1); | ||
| 1236 | #endif | ||
| 1237 | |||
| 1216 | while (n < 0) | 1238 | while (n < 0) |
| 1217 | { | 1239 | { |
| 1218 | ptrdiff_t val; | 1240 | ptrdiff_t val; |
| @@ -1254,6 +1276,9 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1254 | else | 1276 | else |
| 1255 | { | 1277 | { |
| 1256 | immediate_quit = 0; | 1278 | immediate_quit = 0; |
| 1279 | #ifdef REL_ALLOC | ||
| 1280 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1281 | #endif | ||
| 1257 | return (n); | 1282 | return (n); |
| 1258 | } | 1283 | } |
| 1259 | n++; | 1284 | n++; |
| @@ -1296,11 +1321,17 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1296 | else | 1321 | else |
| 1297 | { | 1322 | { |
| 1298 | immediate_quit = 0; | 1323 | immediate_quit = 0; |
| 1324 | #ifdef REL_ALLOC | ||
| 1325 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1326 | #endif | ||
| 1299 | return (0 - n); | 1327 | return (0 - n); |
| 1300 | } | 1328 | } |
| 1301 | n--; | 1329 | n--; |
| 1302 | } | 1330 | } |
| 1303 | immediate_quit = 0; | 1331 | immediate_quit = 0; |
| 1332 | #ifdef REL_ALLOC | ||
| 1333 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1334 | #endif | ||
| 1304 | return (pos); | 1335 | return (pos); |
| 1305 | } | 1336 | } |
| 1306 | else /* non-RE case */ | 1337 | else /* non-RE case */ |