aboutsummaryrefslogtreecommitdiffstats
path: root/src/search.c
diff options
context:
space:
mode:
authorPaul Eggert2011-08-04 19:15:35 -0700
committerPaul Eggert2011-08-04 19:15:35 -0700
commit0065d05491ce5981ea20896bb26d21dcd31e6769 (patch)
tree13240167319d4a99ab5eacae4a883258eb2d28de /src/search.c
parent18ab493650d648ab8dca651ea2698861f926e895 (diff)
downloademacs-0065d05491ce5981ea20896bb26d21dcd31e6769.tar.gz
emacs-0065d05491ce5981ea20896bb26d21dcd31e6769.zip
Adjust in response to jan.h.d's comments.
See, for example <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9196#26>.
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c69
1 files changed, 24 insertions, 45 deletions
diff --git a/src/search.c b/src/search.c
index 79ef8b046df..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,17 +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 if (min (PTRDIFF_MAX, SIZE_MAX) - 1 < substed_alloc_size) 2651 ? STRING_BYTES_BOUND
2652 memory_full (SIZE_MAX); 2652 : length * 2 + 100);
2653 substed = (unsigned char *) xmalloc (substed_alloc_size + 1); 2653 substed = (unsigned char *) xmalloc (substed_alloc_size);
2654 substed_len = 0; 2654 substed_len = 0;
2655 2655
2656 /* Go thru NEWTEXT, producing the actual text to insert in 2656 /* Go thru NEWTEXT, producing the actual text to insert in
@@ -2661,7 +2661,7 @@ since only regular expressions have distinguished subexpressions. */)
2661 { 2661 {
2662 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2662 unsigned char str[MAX_MULTIBYTE_LENGTH];
2663 const unsigned char *add_stuff = NULL; 2663 const unsigned char *add_stuff = NULL;
2664 EMACS_INT add_len = 0; 2664 ptrdiff_t add_len = 0;
2665 int idx = -1; 2665 int idx = -1;
2666 2666
2667 if (str_multibyte) 2667 if (str_multibyte)
@@ -2725,7 +2725,7 @@ since only regular expressions have distinguished subexpressions. */)
2725 set up ADD_STUFF and ADD_LEN to point to it. */ 2725 set up ADD_STUFF and ADD_LEN to point to it. */
2726 if (idx >= 0) 2726 if (idx >= 0)
2727 { 2727 {
2728 EMACS_INT begbyte = CHAR_TO_BYTE (search_regs.start[idx]); 2728 ptrdiff_t begbyte = CHAR_TO_BYTE (search_regs.start[idx]);
2729 add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte; 2729 add_len = CHAR_TO_BYTE (search_regs.end[idx]) - begbyte;
2730 if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx]) 2730 if (search_regs.start[idx] < GPT && GPT < search_regs.end[idx])
2731 move_gap (search_regs.start[idx]); 2731 move_gap (search_regs.start[idx]);
@@ -2736,19 +2736,11 @@ since only regular expressions have distinguished subexpressions. */)
2736 is invariably ADD_LEN bytes starting at ADD_STUFF. */ 2736 is invariably ADD_LEN bytes starting at ADD_STUFF. */
2737 2737
2738 /* Make sure SUBSTED is big enough. */ 2738 /* Make sure SUBSTED is big enough. */
2739 if (substed_len + add_len >= substed_alloc_size) 2739 if (substed_alloc_size - substed_len < add_len)
2740 { 2740 substed =
2741 ptrdiff_t add_len_max = 2741 xpalloc (substed, &substed_alloc_size,
2742 min (PTRDIFF_MAX, SIZE_MAX) - 1 - 500 - substed_len; 2742 add_len - (substed_alloc_size - substed_len),
2743 if (add_len_max < add_len) 2743 STRING_BYTES_BOUND, 1);
2744 {
2745 xfree (substed);
2746 memory_full (SIZE_MAX);
2747 }
2748 substed_alloc_size = substed_len + add_len + 500;
2749 substed = (unsigned char *) xrealloc (substed,
2750 substed_alloc_size + 1);
2751 }
2752 2744
2753 /* Now add to the end of SUBSTED. */ 2745 /* Now add to the end of SUBSTED. */
2754 if (add_stuff) 2746 if (add_stuff)
@@ -3000,30 +2992,17 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
3000 2992
3001 if (length > search_regs.num_regs) 2993 if (length > search_regs.num_regs)
3002 { 2994 {
3003 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (regoff_t) < length) 2995 ptrdiff_t num_regs = search_regs.num_regs;
3004 memory_full (SIZE_MAX); 2996 search_regs.start =
3005 2997 xpalloc (search_regs.start, &num_regs, length - num_regs,
3006 if (search_regs.num_regs == 0) 2998 min (PTRDIFF_MAX, UINT_MAX), sizeof (regoff_t));
3007 { 2999 search_regs.end =
3008 search_regs.start 3000 xrealloc (search_regs.end, num_regs * sizeof (regoff_t));
3009 = (regoff_t *) xmalloc (length * sizeof (regoff_t)); 3001
3010 search_regs.end 3002 for (i = search_regs.num_regs; i < num_regs; i++)
3011 = (regoff_t *) xmalloc (length * sizeof (regoff_t));
3012 }
3013 else
3014 {
3015 search_regs.start
3016 = (regoff_t *) xrealloc (search_regs.start,
3017 length * sizeof (regoff_t));
3018 search_regs.end
3019 = (regoff_t *) xrealloc (search_regs.end,
3020 length * sizeof (regoff_t));
3021 }
3022
3023 for (i = search_regs.num_regs; i < length; i++)
3024 search_regs.start[i] = -1; 3003 search_regs.start[i] = -1;
3025 3004
3026 search_regs.num_regs = length; 3005 search_regs.num_regs = num_regs;
3027 } 3006 }
3028 3007
3029 for (i = 0; CONSP (list); i++) 3008 for (i = 0; CONSP (list); i++)