-2011-08-15 Paul Eggert <eggert@cs.ucla.edu>
+2011-08-16 Paul Eggert <eggert@cs.ucla.edu>
Integer and memory overflow issues (Bug#9196).
+ * image.c (x_allocate_bitmap_record, cache_image):
+ * xselect.c (Fx_register_dnd_atom):
+ Simplify previous changes by using xpalloc.
+
* buffer.c (overlay_str_len): Now ptrdiff_t, not EMACS_INT,
since either will do and ptrdiff_t is convenient with xpalloc.
Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
ptrdiff_t i;
- if (dpyinfo->bitmaps == NULL)
- {
- dpyinfo->bitmaps
- = (Bitmap_Record *) xmalloc (10 * sizeof (Bitmap_Record));
- dpyinfo->bitmaps_size = 10;
- dpyinfo->bitmaps_last = 1;
- return 1;
- }
-
if (dpyinfo->bitmaps_last < dpyinfo->bitmaps_size)
return ++dpyinfo->bitmaps_last;
if (dpyinfo->bitmaps[i].refcount == 0)
return i + 1;
- if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Bitmap_Record) / 2
- < dpyinfo->bitmaps_size)
- memory_full (SIZE_MAX);
- dpyinfo->bitmaps
- = (Bitmap_Record *) xrealloc (dpyinfo->bitmaps,
- (dpyinfo->bitmaps_size
- * (2 * sizeof (Bitmap_Record))));
- dpyinfo->bitmaps_size *= 2;
+ dpyinfo->bitmaps =
+ xpalloc (dpyinfo->bitmaps, &dpyinfo->bitmaps_size,
+ 10, -1, sizeof *dpyinfo->bitmaps);
return ++dpyinfo->bitmaps_last;
}
/* If no free slot found, maybe enlarge c->images. */
if (i == c->used && c->used == c->size)
- {
- if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *c->images / 2 < c->size)
- memory_full (SIZE_MAX);
- c->images =
- (struct image **) xrealloc (c->images,
- c->size * (2 * sizeof *c->images));
- c->size *= 2;
- }
+ c->images = xpalloc (c->images, &c->size, 1, -1, sizeof *c->images);
/* Add IMG to c->images, and assign IMG an id. */
c->images[i] = img;
return Qnil;
if (dpyinfo->x_dnd_atoms_length == dpyinfo->x_dnd_atoms_size)
- {
- if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *dpyinfo->x_dnd_atoms / 2
- < dpyinfo->x_dnd_atoms_size)
- memory_full (SIZE_MAX);
- dpyinfo->x_dnd_atoms = xrealloc (dpyinfo->x_dnd_atoms,
- (2 * sizeof *dpyinfo->x_dnd_atoms
- * dpyinfo->x_dnd_atoms_size));
- dpyinfo->x_dnd_atoms_size *= 2;
- }
+ dpyinfo->x_dnd_atoms =
+ xpalloc (dpyinfo->x_dnd_atoms, &dpyinfo->x_dnd_atoms_size,
+ 1, -1, sizeof *dpyinfo->x_dnd_atoms);
dpyinfo->x_dnd_atoms[dpyinfo->x_dnd_atoms_length++] = x_atom;
return Qnil;