From a69fbedbd629c3e46a23095486617482fb1228c5 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 16 Aug 2011 11:44:32 -0700 Subject: [PATCH] Simplify previous changes. * image.c (x_allocate_bitmap_record, cache_image): * xselect.c (Fx_register_dnd_atom): Simplify previous changes by using xpalloc. --- src/ChangeLog | 6 +++++- src/image.c | 29 ++++------------------------- src/xselect.c | 12 +++--------- 3 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 82851374283..6866daf9f38 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,7 +1,11 @@ -2011-08-15 Paul Eggert +2011-08-16 Paul Eggert 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. diff --git a/src/image.c b/src/image.c index 2f39b896c0b..d10fdad1c54 100644 --- a/src/image.c +++ b/src/image.c @@ -216,15 +216,6 @@ x_allocate_bitmap_record (FRAME_PTR f) 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; @@ -232,14 +223,9 @@ x_allocate_bitmap_record (FRAME_PTR f) 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; } @@ -1836,14 +1822,7 @@ cache_image (struct frame *f, struct image *img) /* 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; diff --git a/src/xselect.c b/src/xselect.c index f5505beffc6..77bda79007c 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -2461,15 +2461,9 @@ FRAME is on. If FRAME is nil, the selected frame is used. */) 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; -- 2.39.5