aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog11
-rw-r--r--src/buffer.c38
-rw-r--r--src/buffer.h10
-rw-r--r--src/editfns.c8
-rw-r--r--src/textprop.c2
-rw-r--r--src/xdisp.c7
-rw-r--r--src/xfaces.c2
7 files changed, 44 insertions, 34 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 41b2fe9aab0..875dcb85168 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,16 @@
12011-06-21 Paul Eggert <eggert@cs.ucla.edu> 12011-06-21 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 Use ptrdiff_t, not int, for overlay counts.
4 * buffer.h (overlays_at, sort_overlays, GET_OVERLAYS_AT):
5 * editfns.c (overlays_around, get_pos_property):
6 * textprop.c (get_char_property_and_overlay):
7 * xdisp.c (next_overlay_change, note_mouse_highlight):
8 * xfaces.c (face_at_buffer_position):
9 * buffer.c (overlays_at, sort_overlays, Foverlays_at)
10 (Fnext_overlay_change, Fprevious_overlay_change):
11 Use ptrdiff_t, not int, for sizes.
12 (overlays_at): Check for size-calculation overflow.
13
3 * xterm.c (xim_initialize, same_x_server): Strlen may not fit in int. 14 * xterm.c (xim_initialize, same_x_server): Strlen may not fit in int.
4 15
5 * xsmfns.c (smc_save_yourself_CB, x_session_initialize): Avoid strlen. 16 * xsmfns.c (smc_save_yourself_CB, x_session_initialize): Avoid strlen.
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
diff --git a/src/buffer.h b/src/buffer.h
index a13351b5ea6..4643e0d9d0e 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -887,10 +887,10 @@ extern struct buffer buffer_local_symbols;
887extern void delete_all_overlays (struct buffer *); 887extern void delete_all_overlays (struct buffer *);
888extern void reset_buffer (struct buffer *); 888extern void reset_buffer (struct buffer *);
889extern void evaporate_overlays (EMACS_INT); 889extern void evaporate_overlays (EMACS_INT);
890extern int overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, 890extern ptrdiff_t overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
891 int *len_ptr, EMACS_INT *next_ptr, 891 ptrdiff_t *len_ptr, EMACS_INT *next_ptr,
892 EMACS_INT *prev_ptr, int change_req); 892 EMACS_INT *prev_ptr, int change_req);
893extern int sort_overlays (Lisp_Object *, int, struct window *); 893extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *);
894extern void recenter_overlay_lists (struct buffer *, EMACS_INT); 894extern void recenter_overlay_lists (struct buffer *, EMACS_INT);
895extern EMACS_INT overlay_strings (EMACS_INT, struct window *, unsigned char **); 895extern EMACS_INT overlay_strings (EMACS_INT, struct window *, unsigned char **);
896extern void validate_region (Lisp_Object *, Lisp_Object *); 896extern void validate_region (Lisp_Object *, Lisp_Object *);
@@ -908,7 +908,7 @@ extern void mmap_set_vars (int);
908 908
909#define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \ 909#define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \
910 do { \ 910 do { \
911 int maxlen = 40; \ 911 ptrdiff_t maxlen = 40; \
912 overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \ 912 overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \
913 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \ 913 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \
914 nextp, NULL, chrq); \ 914 nextp, NULL, chrq); \
diff --git a/src/editfns.c b/src/editfns.c
index f0f8c9eb63f..c0c0e530265 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -331,13 +331,13 @@ If you set the marker not to point anywhere, the buffer will have no mark. */)
331 Return the number found, and store them in a vector in VEC 331 Return the number found, and store them in a vector in VEC
332 of length LEN. */ 332 of length LEN. */
333 333
334static int 334static ptrdiff_t
335overlays_around (EMACS_INT pos, Lisp_Object *vec, int len) 335overlays_around (EMACS_INT pos, Lisp_Object *vec, ptrdiff_t len)
336{ 336{
337 Lisp_Object overlay, start, end; 337 Lisp_Object overlay, start, end;
338 struct Lisp_Overlay *tail; 338 struct Lisp_Overlay *tail;
339 EMACS_INT startpos, endpos; 339 EMACS_INT startpos, endpos;
340 int idx = 0; 340 ptrdiff_t idx = 0;
341 341
342 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 342 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
343 { 343 {
@@ -405,7 +405,7 @@ get_pos_property (Lisp_Object position, register Lisp_Object prop, Lisp_Object o
405 else 405 else
406 { 406 {
407 EMACS_INT posn = XINT (position); 407 EMACS_INT posn = XINT (position);
408 int noverlays; 408 ptrdiff_t noverlays;
409 Lisp_Object *overlay_vec, tem; 409 Lisp_Object *overlay_vec, tem;
410 struct buffer *obuf = current_buffer; 410 struct buffer *obuf = current_buffer;
411 411
diff --git a/src/textprop.c b/src/textprop.c
index 350892cdad6..dd8695f7af8 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -613,7 +613,7 @@ get_char_property_and_overlay (Lisp_Object position, register Lisp_Object prop,
613 } 613 }
614 if (BUFFERP (object)) 614 if (BUFFERP (object))
615 { 615 {
616 int noverlays; 616 ptrdiff_t noverlays;
617 Lisp_Object *overlay_vec; 617 Lisp_Object *overlay_vec;
618 struct buffer *obuf = current_buffer; 618 struct buffer *obuf = current_buffer;
619 619
diff --git a/src/xdisp.c b/src/xdisp.c
index ae5c334447d..d04ceddacb2 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3062,10 +3062,9 @@ compute_stop_pos (struct it *it)
3062static EMACS_INT 3062static EMACS_INT
3063next_overlay_change (EMACS_INT pos) 3063next_overlay_change (EMACS_INT pos)
3064{ 3064{
3065 int noverlays; 3065 ptrdiff_t i, noverlays;
3066 EMACS_INT endpos; 3066 EMACS_INT endpos;
3067 Lisp_Object *overlays; 3067 Lisp_Object *overlays;
3068 int i;
3069 3068
3070 /* Get all overlays at the given position. */ 3069 /* Get all overlays at the given position. */
3071 GET_OVERLAYS_AT (pos, overlays, noverlays, &endpos, 1); 3070 GET_OVERLAYS_AT (pos, overlays, noverlays, &endpos, 1);
@@ -25453,13 +25452,13 @@ note_mouse_highlight (struct frame *f, int x, int y)
25453 && XFASTINT (w->last_modified) == BUF_MODIFF (b) 25452 && XFASTINT (w->last_modified) == BUF_MODIFF (b)
25454 && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b)) 25453 && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b))
25455 { 25454 {
25456 int hpos, vpos, i, dx, dy, area; 25455 int hpos, vpos, dx, dy, area;
25457 EMACS_INT pos; 25456 EMACS_INT pos;
25458 struct glyph *glyph; 25457 struct glyph *glyph;
25459 Lisp_Object object; 25458 Lisp_Object object;
25460 Lisp_Object mouse_face = Qnil, position; 25459 Lisp_Object mouse_face = Qnil, position;
25461 Lisp_Object *overlay_vec = NULL; 25460 Lisp_Object *overlay_vec = NULL;
25462 int noverlays; 25461 ptrdiff_t i, noverlays;
25463 struct buffer *obuf; 25462 struct buffer *obuf;
25464 EMACS_INT obegv, ozv; 25463 EMACS_INT obegv, ozv;
25465 int same_region; 25464 int same_region;
diff --git a/src/xfaces.c b/src/xfaces.c
index 78ea913526e..951cf69a4cb 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -5934,7 +5934,7 @@ face_at_buffer_position (struct window *w, EMACS_INT pos,
5934 struct frame *f = XFRAME (w->frame); 5934 struct frame *f = XFRAME (w->frame);
5935 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 5935 Lisp_Object attrs[LFACE_VECTOR_SIZE];
5936 Lisp_Object prop, position; 5936 Lisp_Object prop, position;
5937 int i, noverlays; 5937 ptrdiff_t i, noverlays;
5938 Lisp_Object *overlay_vec; 5938 Lisp_Object *overlay_vec;
5939 Lisp_Object frame; 5939 Lisp_Object frame;
5940 EMACS_INT endpos; 5940 EMACS_INT endpos;