2011-06-21 Paul Eggert <eggert@cs.ucla.edu>
+ Use ptrdiff_t, not int, for overlay counts.
+ * buffer.h (overlays_at, sort_overlays, GET_OVERLAYS_AT):
+ * editfns.c (overlays_around, get_pos_property):
+ * textprop.c (get_char_property_and_overlay):
+ * xdisp.c (next_overlay_change, note_mouse_highlight):
+ * xfaces.c (face_at_buffer_position):
+ * buffer.c (overlays_at, sort_overlays, Foverlays_at)
+ (Fnext_overlay_change, Fprevious_overlay_change):
+ Use ptrdiff_t, not int, for sizes.
+ (overlays_at): Check for size-calculation overflow.
+
* xterm.c (xim_initialize, same_x_server): Strlen may not fit in int.
* xsmfns.c (smc_save_yourself_CB, x_session_initialize): Avoid strlen.
*NEXT_PTR is guaranteed to be not equal to POS, unless it is the
default (BEGV or ZV). */
-int
-overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, int *len_ptr,
+ptrdiff_t
+overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
+ ptrdiff_t *len_ptr,
EMACS_INT *next_ptr, EMACS_INT *prev_ptr, int change_req)
{
Lisp_Object overlay, start, end;
struct Lisp_Overlay *tail;
- int idx = 0;
- int len = *len_ptr;
+ ptrdiff_t idx = 0;
+ ptrdiff_t len = *len_ptr;
Lisp_Object *vec = *vec_ptr;
EMACS_INT next = ZV;
EMACS_INT prev = BEGV;
int inhibit_storing = 0;
+ ptrdiff_t len_lim = min (MOST_POSITIVE_FIXNUM,
+ min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object));
for (tail = current_buffer->overlays_before; tail; tail = tail->next)
{
Either make it bigger, or don't store any more in it. */
if (extend)
{
+ if ((len_lim - 4) / 2 < len)
+ memory_full (SIZE_MAX);
/* Make it work with an initial len == 0. */
- len *= 2;
- if (len == 0)
- len = 4;
+ len = len * 2 + 4;
*len_ptr = len;
vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
*vec_ptr = vec;
{
if (extend)
{
+ if ((len_lim - 4) / 2 < len)
+ memory_full (SIZE_MAX);
/* Make it work with an initial len == 0. */
- len *= 2;
- if (len == 0)
- len = 4;
+ len = len * 2 + 4;
*len_ptr = len;
vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
*vec_ptr = vec;
/* Sort an array of overlays by priority. The array is modified in place.
The return value is the new size; this may be smaller than the original
size if some of the overlays were invalid or were window-specific. */
-int
-sort_overlays (Lisp_Object *overlay_vec, int noverlays, struct window *w)
+ptrdiff_t
+sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w)
{
- int i, j;
+ ptrdiff_t i, j;
struct sortvec *sortvec;
sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec));
doc: /* Return a list of the overlays that contain the character at POS. */)
(Lisp_Object pos)
{
- int noverlays;
+ ptrdiff_t len, noverlays;
Lisp_Object *overlay_vec;
- int len;
Lisp_Object result;
CHECK_NUMBER_COERCE_MARKER (pos);
the value is (point-max). */)
(Lisp_Object pos)
{
- int noverlays;
+ ptrdiff_t i, len, noverlays;
EMACS_INT endpos;
Lisp_Object *overlay_vec;
- int len;
- int i;
CHECK_NUMBER_COERCE_MARKER (pos);
{
EMACS_INT prevpos;
Lisp_Object *overlay_vec;
- int len;
+ ptrdiff_t len;
CHECK_NUMBER_COERCE_MARKER (pos);
extern void delete_all_overlays (struct buffer *);
extern void reset_buffer (struct buffer *);
extern void evaporate_overlays (EMACS_INT);
-extern int overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
- int *len_ptr, EMACS_INT *next_ptr,
- EMACS_INT *prev_ptr, int change_req);
-extern int sort_overlays (Lisp_Object *, int, struct window *);
+extern ptrdiff_t overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
+ ptrdiff_t *len_ptr, EMACS_INT *next_ptr,
+ EMACS_INT *prev_ptr, int change_req);
+extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *);
extern void recenter_overlay_lists (struct buffer *, EMACS_INT);
extern EMACS_INT overlay_strings (EMACS_INT, struct window *, unsigned char **);
extern void validate_region (Lisp_Object *, Lisp_Object *);
#define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \
do { \
- int maxlen = 40; \
+ ptrdiff_t maxlen = 40; \
overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \
noverlays = overlays_at (posn, 0, &overlays, &maxlen, \
nextp, NULL, chrq); \
Return the number found, and store them in a vector in VEC
of length LEN. */
-static int
-overlays_around (EMACS_INT pos, Lisp_Object *vec, int len)
+static ptrdiff_t
+overlays_around (EMACS_INT pos, Lisp_Object *vec, ptrdiff_t len)
{
Lisp_Object overlay, start, end;
struct Lisp_Overlay *tail;
EMACS_INT startpos, endpos;
- int idx = 0;
+ ptrdiff_t idx = 0;
for (tail = current_buffer->overlays_before; tail; tail = tail->next)
{
else
{
EMACS_INT posn = XINT (position);
- int noverlays;
+ ptrdiff_t noverlays;
Lisp_Object *overlay_vec, tem;
struct buffer *obuf = current_buffer;
}
if (BUFFERP (object))
{
- int noverlays;
+ ptrdiff_t noverlays;
Lisp_Object *overlay_vec;
struct buffer *obuf = current_buffer;
static EMACS_INT
next_overlay_change (EMACS_INT pos)
{
- int noverlays;
+ ptrdiff_t i, noverlays;
EMACS_INT endpos;
Lisp_Object *overlays;
- int i;
/* Get all overlays at the given position. */
GET_OVERLAYS_AT (pos, overlays, noverlays, &endpos, 1);
&& XFASTINT (w->last_modified) == BUF_MODIFF (b)
&& XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b))
{
- int hpos, vpos, i, dx, dy, area;
+ int hpos, vpos, dx, dy, area;
EMACS_INT pos;
struct glyph *glyph;
Lisp_Object object;
Lisp_Object mouse_face = Qnil, position;
Lisp_Object *overlay_vec = NULL;
- int noverlays;
+ ptrdiff_t i, noverlays;
struct buffer *obuf;
EMACS_INT obegv, ozv;
int same_region;
struct frame *f = XFRAME (w->frame);
Lisp_Object attrs[LFACE_VECTOR_SIZE];
Lisp_Object prop, position;
- int i, noverlays;
+ ptrdiff_t i, noverlays;
Lisp_Object *overlay_vec;
Lisp_Object frame;
EMACS_INT endpos;