diff options
Diffstat (limited to 'src/search.c')
| -rw-r--r-- | src/search.c | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/src/search.c b/src/search.c index a56df784cd2..d892792cbaa 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -683,7 +683,7 @@ scan_buffer (register int target, EMACS_INT start, EMACS_INT end, | |||
| 683 | to see where we can avoid some scanning. */ | 683 | to see where we can avoid some scanning. */ |
| 684 | if (target == '\n' && newline_cache) | 684 | if (target == '\n' && newline_cache) |
| 685 | { | 685 | { |
| 686 | EMACS_INT next_change; | 686 | ptrdiff_t next_change; |
| 687 | immediate_quit = 0; | 687 | immediate_quit = 0; |
| 688 | while (region_cache_forward | 688 | while (region_cache_forward |
| 689 | (current_buffer, newline_cache, start_byte, &next_change)) | 689 | (current_buffer, newline_cache, start_byte, &next_change)) |
| @@ -755,7 +755,7 @@ scan_buffer (register int target, EMACS_INT start, EMACS_INT end, | |||
| 755 | /* Consult the newline cache, if appropriate. */ | 755 | /* Consult the newline cache, if appropriate. */ |
| 756 | if (target == '\n' && newline_cache) | 756 | if (target == '\n' && newline_cache) |
| 757 | { | 757 | { |
| 758 | EMACS_INT next_change; | 758 | ptrdiff_t next_change; |
| 759 | immediate_quit = 0; | 759 | immediate_quit = 0; |
| 760 | while (region_cache_backward | 760 | while (region_cache_backward |
| 761 | (current_buffer, newline_cache, start_byte, &next_change)) | 761 | (current_buffer, newline_cache, start_byte, &next_change)) |
| @@ -2640,15 +2640,17 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2640 | perform substitution on the replacement string. */ | 2640 | perform substitution on the replacement string. */ |
| 2641 | if (NILP (literal)) | 2641 | if (NILP (literal)) |
| 2642 | { | 2642 | { |
| 2643 | EMACS_INT length = SBYTES (newtext); | 2643 | ptrdiff_t length = SBYTES (newtext); |
| 2644 | unsigned char *substed; | 2644 | unsigned char *substed; |
| 2645 | EMACS_INT substed_alloc_size, substed_len; | 2645 | ptrdiff_t substed_alloc_size, substed_len; |
| 2646 | int buf_multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); | 2646 | int buf_multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); |
| 2647 | int str_multibyte = STRING_MULTIBYTE (newtext); | 2647 | int str_multibyte = STRING_MULTIBYTE (newtext); |
| 2648 | int really_changed = 0; | 2648 | int really_changed = 0; |
| 2649 | 2649 | ||
| 2650 | substed_alloc_size = length * 2 + 100; | 2650 | substed_alloc_size = ((STRING_BYTES_BOUND - 100) / 2 < length |
| 2651 | substed = (unsigned char *) xmalloc (substed_alloc_size + 1); | 2651 | ? STRING_BYTES_BOUND |
| 2652 | : length * 2 + 100); | ||
| 2653 | substed = (unsigned char *) xmalloc (substed_alloc_size); | ||
| 2652 | substed_len = 0; | 2654 | substed_len = 0; |
| 2653 | 2655 | ||
| 2654 | /* Go thru NEWTEXT, producing the actual text to insert in | 2656 | /* Go thru NEWTEXT, producing the actual text to insert in |
| @@ -2659,7 +2661,7 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2659 | { | 2661 | { |
| 2660 | unsigned char str[MAX_MULTIBYTE_LENGTH]; | 2662 | unsigned char str[MAX_MULTIBYTE_LENGTH]; |
| 2661 | const unsigned char *add_stuff = NULL; | 2663 | const unsigned char *add_stuff = NULL; |
| 2662 | EMACS_INT add_len = 0; | 2664 | ptrdiff_t add_len = 0; |
| 2663 | int idx = -1; | 2665 | int idx = -1; |
| 2664 | 2666 | ||
| 2665 | if (str_multibyte) | 2667 | if (str_multibyte) |
| @@ -2723,7 +2725,7 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2723 | set up ADD_STUFF and ADD_LEN to point to it. */ | 2725 | set up ADD_STUFF and ADD_LEN to point to it. */ |
| 2724 | if (idx >= 0) | 2726 | if (idx >= 0) |
| 2725 | { | 2727 | { |
| 2726 | EMACS_INT begbyte = CHAR_TO_BYTE (search_regs.start[idx]); | 2728 | ptrdiff_t begbyte = CHAR_TO_BYTE (search_regs.start[idx]); |
| 2727 | add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte; | 2729 | add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte; |
| 2728 | if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx]) | 2730 | if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx]) |
| 2729 | move_gap (search_regs.start[idx]); | 2731 | move_gap (search_regs.start[idx]); |
| @@ -2734,12 +2736,11 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2734 | is invariably ADD_LEN bytes starting at ADD_STUFF. */ | 2736 | is invariably ADD_LEN bytes starting at ADD_STUFF. */ |
| 2735 | 2737 | ||
| 2736 | /* Make sure SUBSTED is big enough. */ | 2738 | /* Make sure SUBSTED is big enough. */ |
| 2737 | if (substed_len + add_len >= substed_alloc_size) | 2739 | if (substed_alloc_size - substed_len < add_len) |
| 2738 | { | 2740 | substed = |
| 2739 | substed_alloc_size = substed_len + add_len + 500; | 2741 | xpalloc (substed, &substed_alloc_size, |
| 2740 | substed = (unsigned char *) xrealloc (substed, | 2742 | add_len - (substed_alloc_size - substed_len), |
| 2741 | substed_alloc_size + 1); | 2743 | STRING_BYTES_BOUND, 1); |
| 2742 | } | ||
| 2743 | 2744 | ||
| 2744 | /* Now add to the end of SUBSTED. */ | 2745 | /* Now add to the end of SUBSTED. */ |
| 2745 | if (add_stuff) | 2746 | if (add_stuff) |
| @@ -2973,7 +2974,7 @@ LIST should have been created by calling `match-data' previously. | |||
| 2973 | If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) | 2974 | If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) |
| 2974 | (register Lisp_Object list, Lisp_Object reseat) | 2975 | (register Lisp_Object list, Lisp_Object reseat) |
| 2975 | { | 2976 | { |
| 2976 | register int i; | 2977 | ptrdiff_t i; |
| 2977 | register Lisp_Object marker; | 2978 | register Lisp_Object marker; |
| 2978 | 2979 | ||
| 2979 | if (running_asynch_code) | 2980 | if (running_asynch_code) |
| @@ -2987,31 +2988,21 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) | |||
| 2987 | 2988 | ||
| 2988 | /* Allocate registers if they don't already exist. */ | 2989 | /* Allocate registers if they don't already exist. */ |
| 2989 | { | 2990 | { |
| 2990 | int length = XFASTINT (Flength (list)) / 2; | 2991 | ptrdiff_t length = XFASTINT (Flength (list)) / 2; |
| 2991 | 2992 | ||
| 2992 | if (length > search_regs.num_regs) | 2993 | if (length > search_regs.num_regs) |
| 2993 | { | 2994 | { |
| 2994 | if (search_regs.num_regs == 0) | 2995 | ptrdiff_t num_regs = search_regs.num_regs; |
| 2995 | { | 2996 | search_regs.start = |
| 2996 | search_regs.start | 2997 | xpalloc (search_regs.start, &num_regs, length - num_regs, |
| 2997 | = (regoff_t *) xmalloc (length * sizeof (regoff_t)); | 2998 | min (PTRDIFF_MAX, UINT_MAX), sizeof (regoff_t)); |
| 2998 | search_regs.end | 2999 | search_regs.end = |
| 2999 | = (regoff_t *) xmalloc (length * sizeof (regoff_t)); | 3000 | xrealloc (search_regs.end, num_regs * sizeof (regoff_t)); |
| 3000 | } | 3001 | |
| 3001 | else | 3002 | for (i = search_regs.num_regs; i < num_regs; i++) |
| 3002 | { | ||
| 3003 | search_regs.start | ||
| 3004 | = (regoff_t *) xrealloc (search_regs.start, | ||
| 3005 | length * sizeof (regoff_t)); | ||
| 3006 | search_regs.end | ||
| 3007 | = (regoff_t *) xrealloc (search_regs.end, | ||
| 3008 | length * sizeof (regoff_t)); | ||
| 3009 | } | ||
| 3010 | |||
| 3011 | for (i = search_regs.num_regs; i < length; i++) | ||
| 3012 | search_regs.start[i] = -1; | 3003 | search_regs.start[i] = -1; |
| 3013 | 3004 | ||
| 3014 | search_regs.num_regs = length; | 3005 | search_regs.num_regs = num_regs; |
| 3015 | } | 3006 | } |
| 3016 | 3007 | ||
| 3017 | for (i = 0; CONSP (list); i++) | 3008 | for (i = 0; CONSP (list); i++) |