aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/buffer.c b/src/buffer.c
index fb9b15e4c70..b8f85d1a1cd 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2518,18 +2518,21 @@ swap_out_buffer_local_variables (struct buffer *b)
2518 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the 2518 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the
2519 default (BEGV or ZV). */ 2519 default (BEGV or ZV). */
2520 2520
2521int 2521ptrdiff_t
2522overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, int *len_ptr, 2522overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2523 ptrdiff_t *len_ptr,
2523 EMACS_INT *next_ptr, EMACS_INT *prev_ptr, int change_req) 2524 EMACS_INT *next_ptr, EMACS_INT *prev_ptr, int change_req)
2524{ 2525{
2525 Lisp_Object overlay, start, end; 2526 Lisp_Object overlay, start, end;
2526 struct Lisp_Overlay *tail; 2527 struct Lisp_Overlay *tail;
2527 int idx = 0; 2528 ptrdiff_t idx = 0;
2528 int len = *len_ptr; 2529 ptrdiff_t len = *len_ptr;
2529 Lisp_Object *vec = *vec_ptr; 2530 Lisp_Object *vec = *vec_ptr;
2530 EMACS_INT next = ZV; 2531 EMACS_INT next = ZV;
2531 EMACS_INT prev = BEGV; 2532 EMACS_INT prev = BEGV;
2532 int inhibit_storing = 0; 2533 int inhibit_storing = 0;
2534 ptrdiff_t len_lim = min (MOST_POSITIVE_FIXNUM,
2535 min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object));
2533 2536
2534 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 2537 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
2535 { 2538 {
@@ -2561,10 +2564,10 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, int *len_ptr,
2561 Either make it bigger, or don't store any more in it. */ 2564 Either make it bigger, or don't store any more in it. */
2562 if (extend) 2565 if (extend)
2563 { 2566 {
2567 if ((len_lim - 4) / 2 < len)
2568 memory_full (SIZE_MAX);
2564 /* Make it work with an initial len == 0. */ 2569 /* Make it work with an initial len == 0. */
2565 len *= 2; 2570 len = len * 2 + 4;
2566 if (len == 0)
2567 len = 4;
2568 *len_ptr = len; 2571 *len_ptr = len;
2569 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); 2572 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
2570 *vec_ptr = vec; 2573 *vec_ptr = vec;
@@ -2604,10 +2607,10 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, int *len_ptr,
2604 { 2607 {
2605 if (extend) 2608 if (extend)
2606 { 2609 {
2610 if ((len_lim - 4) / 2 < len)
2611 memory_full (SIZE_MAX);
2607 /* Make it work with an initial len == 0. */ 2612 /* Make it work with an initial len == 0. */
2608 len *= 2; 2613 len = len * 2 + 4;
2609 if (len == 0)
2610 len = 4;
2611 *len_ptr = len; 2614 *len_ptr = len;
2612 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); 2615 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
2613 *vec_ptr = vec; 2616 *vec_ptr = vec;
@@ -2871,10 +2874,10 @@ compare_overlays (const void *v1, const void *v2)
2871/* Sort an array of overlays by priority. The array is modified in place. 2874/* Sort an array of overlays by priority. The array is modified in place.
2872 The return value is the new size; this may be smaller than the original 2875 The return value is the new size; this may be smaller than the original
2873 size if some of the overlays were invalid or were window-specific. */ 2876 size if some of the overlays were invalid or were window-specific. */
2874int 2877ptrdiff_t
2875sort_overlays (Lisp_Object *overlay_vec, int noverlays, struct window *w) 2878sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w)
2876{ 2879{
2877 int i, j; 2880 ptrdiff_t i, j;
2878 struct sortvec *sortvec; 2881 struct sortvec *sortvec;
2879 sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec)); 2882 sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec));
2880 2883
@@ -3880,9 +3883,8 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
3880 doc: /* Return a list of the overlays that contain the character at POS. */) 3883 doc: /* Return a list of the overlays that contain the character at POS. */)
3881 (Lisp_Object pos) 3884 (Lisp_Object pos)
3882{ 3885{
3883 int noverlays; 3886 ptrdiff_t len, noverlays;
3884 Lisp_Object *overlay_vec; 3887 Lisp_Object *overlay_vec;
3885 int len;
3886 Lisp_Object result; 3888 Lisp_Object result;
3887 3889
3888 CHECK_NUMBER_COERCE_MARKER (pos); 3890 CHECK_NUMBER_COERCE_MARKER (pos);
@@ -3942,11 +3944,9 @@ If there are no overlay boundaries from POS to (point-max),
3942the value is (point-max). */) 3944the value is (point-max). */)
3943 (Lisp_Object pos) 3945 (Lisp_Object pos)
3944{ 3946{
3945 int noverlays; 3947 ptrdiff_t i, len, noverlays;
3946 EMACS_INT endpos; 3948 EMACS_INT endpos;
3947 Lisp_Object *overlay_vec; 3949 Lisp_Object *overlay_vec;
3948 int len;
3949 int i;
3950 3950
3951 CHECK_NUMBER_COERCE_MARKER (pos); 3951 CHECK_NUMBER_COERCE_MARKER (pos);
3952 3952
@@ -3985,7 +3985,7 @@ the value is (point-min). */)
3985{ 3985{
3986 EMACS_INT prevpos; 3986 EMACS_INT prevpos;
3987 Lisp_Object *overlay_vec; 3987 Lisp_Object *overlay_vec;
3988 int len; 3988 ptrdiff_t len;
3989 3989
3990 CHECK_NUMBER_COERCE_MARKER (pos); 3990 CHECK_NUMBER_COERCE_MARKER (pos);
3991 3991