aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
authorDmitry Antipov2012-07-05 10:32:41 +0400
committerDmitry Antipov2012-07-05 10:32:41 +0400
commit23f86fce48e1cc8118f0ea5cce49d1acfd4364c4 (patch)
tree837ae05f1ad4ad92936f804d580d95751779befe /src/image.c
parent0497dc44b44f148425ff76c4cb7ef0d2ead9750b (diff)
downloademacs-23f86fce48e1cc8118f0ea5cce49d1acfd4364c4.tar.gz
emacs-23f86fce48e1cc8118f0ea5cce49d1acfd4364c4.zip
Cleanup xmalloc.
* admin/coccinelle/xzalloc.cocci: Semantic patch to convert calls to xmalloc with following memset to xzalloc. * src/lisp.h (xzalloc): New prototype. Omit needless casts. * src/alloc.c (xzalloc): New function. Omit needless casts. * src/charset.c: Omit needless casts. Convert all calls to malloc with following memset to xzalloc. * src/dispnew.c: Likewise. * src/fringe.c: Likewise. * src/image.c: Likewise. * src/sound.c: Likewise. * src/term.c: Likewise. * src/w32fns.c: Likewise. * src/w32font.c: Likewise. * src/w32term.c: Likewise. * src/xfaces.c: Likewise. * src/xfns.c: Likewise. * src/xterm.c: Likewise. * src/atimer.c: Omit needless casts. * src/buffer.c: Likewise. * src/callproc.c: Likewise. * src/ccl.c: Likewise. * src/coding.c: Likewise. * src/composite.c: Likewise. * src/doc.c: Likewise. * src/doprnt.c: Likewise. * src/editfns.c: Likewise. * src/emacs.c: Likewise. * src/eval.c: Likewise. * src/filelock.c: Likewise. * src/fns.c: Likewise. * src/gtkutil.c: Likewise. * src/keyboard.c: Likewise. * src/lisp.h: Likewise. * src/lread.c: Likewise. * src/minibuf.c: Likewise. * src/msdos.c: Likewise. * src/print.c: Likewise. * src/process.c: Likewise. * src/region-cache.c: Likewise. * src/search.c: Likewise. * src/sysdep.c: Likewise. * src/termcap.c: Likewise. * src/terminal.c: Likewise. * src/tparam.c: Likewise. * src/w16select.c: Likewise. * src/w32.c: Likewise. * src/w32reg.c: Likewise. * src/w32select.c: Likewise. * src/w32uniscribe.c: Likewise. * src/widget.c: Likewise. * src/xdisp.c: Likewise. * src/xmenu.c: Likewise. * src/xrdb.c: Likewise. * src/xselect.c: Likewise.
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c55
1 files changed, 24 insertions, 31 deletions
diff --git a/src/image.c b/src/image.c
index d67faff1821..45dcb554439 100644
--- a/src/image.c
+++ b/src/image.c
@@ -319,7 +319,7 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
319 id = x_allocate_bitmap_record (f); 319 id = x_allocate_bitmap_record (f);
320 dpyinfo->bitmaps[id - 1].img = bitmap; 320 dpyinfo->bitmaps[id - 1].img = bitmap;
321 dpyinfo->bitmaps[id - 1].refcount = 1; 321 dpyinfo->bitmaps[id - 1].refcount = 1;
322 dpyinfo->bitmaps[id - 1].file = (char *) xmalloc (SBYTES (file) + 1); 322 dpyinfo->bitmaps[id - 1].file = xmalloc (SBYTES (file) + 1);
323 dpyinfo->bitmaps[id - 1].depth = 1; 323 dpyinfo->bitmaps[id - 1].depth = 1;
324 dpyinfo->bitmaps[id - 1].height = ns_image_width (bitmap); 324 dpyinfo->bitmaps[id - 1].height = ns_image_width (bitmap);
325 dpyinfo->bitmaps[id - 1].width = ns_image_height (bitmap); 325 dpyinfo->bitmaps[id - 1].width = ns_image_height (bitmap);
@@ -365,7 +365,7 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
365 dpyinfo->bitmaps[id - 1].pixmap = bitmap; 365 dpyinfo->bitmaps[id - 1].pixmap = bitmap;
366 dpyinfo->bitmaps[id - 1].have_mask = 0; 366 dpyinfo->bitmaps[id - 1].have_mask = 0;
367 dpyinfo->bitmaps[id - 1].refcount = 1; 367 dpyinfo->bitmaps[id - 1].refcount = 1;
368 dpyinfo->bitmaps[id - 1].file = (char *) xmalloc (SBYTES (file) + 1); 368 dpyinfo->bitmaps[id - 1].file = xmalloc (SBYTES (file) + 1);
369 dpyinfo->bitmaps[id - 1].depth = 1; 369 dpyinfo->bitmaps[id - 1].depth = 1;
370 dpyinfo->bitmaps[id - 1].height = height; 370 dpyinfo->bitmaps[id - 1].height = height;
371 dpyinfo->bitmaps[id - 1].width = width; 371 dpyinfo->bitmaps[id - 1].width = width;
@@ -599,7 +599,7 @@ define_image_type (struct image_type *type, int loaded)
599 { 599 {
600 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs. 600 /* Make a copy of TYPE to avoid a bus error in a dumped Emacs.
601 The initialized data segment is read-only. */ 601 The initialized data segment is read-only. */
602 struct image_type *p = (struct image_type *) xmalloc (sizeof *p); 602 struct image_type *p = xmalloc (sizeof *p);
603 memcpy (p, type, sizeof *p); 603 memcpy (p, type, sizeof *p);
604 p->next = image_types; 604 p->next = image_types;
605 image_types = p; 605 image_types = p;
@@ -982,11 +982,10 @@ static void free_image (struct frame *f, struct image *img);
982static struct image * 982static struct image *
983make_image (Lisp_Object spec, EMACS_UINT hash) 983make_image (Lisp_Object spec, EMACS_UINT hash)
984{ 984{
985 struct image *img = (struct image *) xmalloc (sizeof *img); 985 struct image *img = xzalloc (sizeof *img);
986 Lisp_Object file = image_spec_value (spec, QCfile, NULL); 986 Lisp_Object file = image_spec_value (spec, QCfile, NULL);
987 987
988 eassert (valid_image_p (spec)); 988 eassert (valid_image_p (spec));
989 memset (img, 0, sizeof *img);
990 img->dependencies = NILP (file) ? Qnil : list1 (file); 989 img->dependencies = NILP (file) ? Qnil : list1 (file);
991 img->type = lookup_image_type (image_spec_value (spec, QCtype, NULL)); 990 img->type = lookup_image_type (image_spec_value (spec, QCtype, NULL));
992 eassert (img->type != NULL); 991 eassert (img->type != NULL);
@@ -1385,16 +1384,14 @@ static void postprocess_image (struct frame *, struct image *);
1385struct image_cache * 1384struct image_cache *
1386make_image_cache (void) 1385make_image_cache (void)
1387{ 1386{
1388 struct image_cache *c = (struct image_cache *) xmalloc (sizeof *c); 1387 struct image_cache *c = xzalloc (sizeof *c);
1389 int size; 1388 int size;
1390 1389
1391 memset (c, 0, sizeof *c);
1392 size = 50; 1390 size = 50;
1393 c->images = (struct image **) xmalloc (size * sizeof *c->images); 1391 c->images = xmalloc (size * sizeof *c->images);
1394 c->size = size; 1392 c->size = size;
1395 size = IMAGE_CACHE_BUCKETS_SIZE * sizeof *c->buckets; 1393 size = IMAGE_CACHE_BUCKETS_SIZE * sizeof *c->buckets;
1396 c->buckets = (struct image **) xmalloc (size); 1394 c->buckets = xzalloc (size);
1397 memset (c->buckets, 0, size);
1398 return c; 1395 return c;
1399} 1396}
1400 1397
@@ -1969,7 +1966,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
1969 } 1966 }
1970 1967
1971 /* Allocate image raster. */ 1968 /* Allocate image raster. */
1972 (*ximg)->data = (char *) xmalloc ((*ximg)->bytes_per_line * height); 1969 (*ximg)->data = xmalloc ((*ximg)->bytes_per_line * height);
1973 1970
1974 /* Allocate a pixmap of the same size. */ 1971 /* Allocate a pixmap of the same size. */
1975 *pixmap = XCreatePixmap (display, window, width, height, depth); 1972 *pixmap = XCreatePixmap (display, window, width, height, depth);
@@ -2183,7 +2180,7 @@ slurp_file (char *file, ptrdiff_t *size)
2183 if (stat (file, &st) == 0 2180 if (stat (file, &st) == 0
2184 && (fp = fopen (file, "rb")) != NULL 2181 && (fp = fopen (file, "rb")) != NULL
2185 && 0 <= st.st_size && st.st_size <= min (PTRDIFF_MAX, SIZE_MAX) 2182 && 0 <= st.st_size && st.st_size <= min (PTRDIFF_MAX, SIZE_MAX)
2186 && (buf = (unsigned char *) xmalloc (st.st_size), 2183 && (buf = xmalloc (st.st_size),
2187 fread (buf, 1, st.st_size, fp) == st.st_size)) 2184 fread (buf, 1, st.st_size, fp) == st.st_size))
2188 { 2185 {
2189 *size = st.st_size; 2186 *size = st.st_size;
@@ -2705,7 +2702,7 @@ xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *e
2705 } 2702 }
2706 bytes_per_line = (*width + 7) / 8 + padding_p; 2703 bytes_per_line = (*width + 7) / 8 + padding_p;
2707 nbytes = bytes_per_line * *height; 2704 nbytes = bytes_per_line * *height;
2708 p = *data = (char *) xmalloc (nbytes); 2705 p = *data = xmalloc (nbytes);
2709 2706
2710 if (v10) 2707 if (v10)
2711 { 2708 {
@@ -3118,8 +3115,7 @@ static void
3118xpm_init_color_cache (struct frame *f, XpmAttributes *attrs) 3115xpm_init_color_cache (struct frame *f, XpmAttributes *attrs)
3119{ 3116{
3120 size_t nbytes = XPM_COLOR_CACHE_BUCKETS * sizeof *xpm_color_cache; 3117 size_t nbytes = XPM_COLOR_CACHE_BUCKETS * sizeof *xpm_color_cache;
3121 xpm_color_cache = (struct xpm_cached_color **) xmalloc (nbytes); 3118 xpm_color_cache = xzalloc (nbytes);
3122 memset (xpm_color_cache, 0, nbytes);
3123 init_color_table (); 3119 init_color_table ();
3124 3120
3125 if (attrs->valuemask & XpmColorSymbols) 3121 if (attrs->valuemask & XpmColorSymbols)
@@ -3183,7 +3179,7 @@ xpm_cache_color (struct frame *f, char *color_name, XColor *color, int bucket)
3183 bucket = xpm_color_bucket (color_name); 3179 bucket = xpm_color_bucket (color_name);
3184 3180
3185 nbytes = offsetof (struct xpm_cached_color, name) + strlen (color_name) + 1; 3181 nbytes = offsetof (struct xpm_cached_color, name) + strlen (color_name) + 1;
3186 p = (struct xpm_cached_color *) xmalloc (nbytes); 3182 p = xmalloc (nbytes);
3187 strcpy (p->name, color_name); 3183 strcpy (p->name, color_name);
3188 p->color = *color; 3184 p->color = *color;
3189 p->next = xpm_color_cache[bucket]; 3185 p->next = xpm_color_cache[bucket];
@@ -4154,8 +4150,7 @@ static void
4154init_color_table (void) 4150init_color_table (void)
4155{ 4151{
4156 int size = CT_SIZE * sizeof (*ct_table); 4152 int size = CT_SIZE * sizeof (*ct_table);
4157 ct_table = (struct ct_color **) xmalloc (size); 4153 ct_table = xzalloc (size);
4158 memset (ct_table, 0, size);
4159 ct_colors_allocated = 0; 4154 ct_colors_allocated = 0;
4160} 4155}
4161 4156
@@ -4250,7 +4245,7 @@ lookup_rgb_color (struct frame *f, int r, int g, int b)
4250 if (rc) 4245 if (rc)
4251 { 4246 {
4252 ++ct_colors_allocated; 4247 ++ct_colors_allocated;
4253 p = (struct ct_color *) xmalloc (sizeof *p); 4248 p = xmalloc (sizeof *p);
4254 p->r = r; 4249 p->r = r;
4255 p->g = g; 4250 p->g = g;
4256 p->b = b; 4251 p->b = b;
@@ -4268,7 +4263,7 @@ lookup_rgb_color (struct frame *f, int r, int g, int b)
4268 color = RGB_TO_ULONG (r, g, b); 4263 color = RGB_TO_ULONG (r, g, b);
4269#endif /* HAVE_NTGUI */ 4264#endif /* HAVE_NTGUI */
4270 ++ct_colors_allocated; 4265 ++ct_colors_allocated;
4271 p = (struct ct_color *) xmalloc (sizeof *p); 4266 p = xmalloc (sizeof *p);
4272 p->r = r; 4267 p->r = r;
4273 p->g = g; 4268 p->g = g;
4274 p->b = b; 4269 p->b = b;
@@ -4323,7 +4318,7 @@ lookup_pixel_color (struct frame *f, unsigned long pixel)
4323 { 4318 {
4324 ++ct_colors_allocated; 4319 ++ct_colors_allocated;
4325 4320
4326 p = (struct ct_color *) xmalloc (sizeof *p); 4321 p = xmalloc (sizeof *p);
4327 p->r = color.red; 4322 p->r = color.red;
4328 p->g = color.green; 4323 p->g = color.green;
4329 p->b = color.blue; 4324 p->b = color.blue;
@@ -4355,8 +4350,7 @@ colors_in_color_table (int *n)
4355 } 4350 }
4356 else 4351 else
4357 { 4352 {
4358 colors = (unsigned long *) xmalloc (ct_colors_allocated 4353 colors = xmalloc (ct_colors_allocated * sizeof *colors);
4359 * sizeof *colors);
4360 *n = ct_colors_allocated; 4354 *n = ct_colors_allocated;
4361 4355
4362 for (i = j = 0; i < CT_SIZE; ++i) 4356 for (i = j = 0; i < CT_SIZE; ++i)
@@ -4445,7 +4439,7 @@ x_to_xcolors (struct frame *f, struct image *img, int rgb_p)
4445 4439
4446 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *colors / img->width < img->height) 4440 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *colors / img->width < img->height)
4447 memory_full (SIZE_MAX); 4441 memory_full (SIZE_MAX);
4448 colors = (XColor *) xmalloc (sizeof *colors * img->width * img->height); 4442 colors = xmalloc (sizeof *colors * img->width * img->height);
4449 4443
4450#ifndef HAVE_NTGUI 4444#ifndef HAVE_NTGUI
4451 /* Get the X image IMG->pixmap. */ 4445 /* Get the X image IMG->pixmap. */
@@ -4599,7 +4593,7 @@ x_detect_edges (struct frame *f, struct image *img, int *matrix, int color_adjus
4599 4593
4600 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *new / img->width < img->height) 4594 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *new / img->width < img->height)
4601 memory_full (SIZE_MAX); 4595 memory_full (SIZE_MAX);
4602 new = (XColor *) xmalloc (sizeof *new * img->width * img->height); 4596 new = xmalloc (sizeof *new * img->width * img->height);
4603 4597
4604 for (y = 0; y < img->height; ++y) 4598 for (y = 0; y < img->height; ++y)
4605 { 4599 {
@@ -4852,8 +4846,7 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
4852#else 4846#else
4853 /* Create the bit array serving as mask. */ 4847 /* Create the bit array serving as mask. */
4854 row_width = (img->width + 7) / 8; 4848 row_width = (img->width + 7) / 8;
4855 mask_img = xmalloc (row_width * img->height); 4849 mask_img = xzalloc (row_width * img->height);
4856 memset (mask_img, 0, row_width * img->height);
4857 4850
4858 /* Create a memory device context for IMG->pixmap. */ 4851 /* Create a memory device context for IMG->pixmap. */
4859 frame_dc = get_frame_dc (f); 4852 frame_dc = get_frame_dc (f);
@@ -5069,7 +5062,7 @@ pbm_read_file (Lisp_Object file, int *size)
5069 if (stat (SDATA (file), &st) == 0 5062 if (stat (SDATA (file), &st) == 0
5070 && (fp = fopen (SDATA (file), "rb")) != NULL 5063 && (fp = fopen (SDATA (file), "rb")) != NULL
5071 && 0 <= st.st_size && st.st_size <= min (PTRDIFF_MAX, SIZE_MAX) 5064 && 0 <= st.st_size && st.st_size <= min (PTRDIFF_MAX, SIZE_MAX)
5072 && (buf = (char *) xmalloc (st.st_size), 5065 && (buf = xmalloc (st.st_size),
5073 fread (buf, 1, st.st_size, fp) == st.st_size)) 5066 fread (buf, 1, st.st_size, fp) == st.st_size))
5074 { 5067 {
5075 *size = st.st_size; 5068 *size = st.st_size;
@@ -5840,8 +5833,8 @@ png_load (struct frame *f, struct image *img)
5840 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *rows < height 5833 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *rows < height
5841 || min (PTRDIFF_MAX, SIZE_MAX) / sizeof *pixels / height < row_bytes) 5834 || min (PTRDIFF_MAX, SIZE_MAX) / sizeof *pixels / height < row_bytes)
5842 memory_full (SIZE_MAX); 5835 memory_full (SIZE_MAX);
5843 pixels = (png_byte *) xmalloc (sizeof *pixels * row_bytes * height); 5836 pixels = xmalloc (sizeof *pixels * row_bytes * height);
5844 rows = (png_byte **) xmalloc (height * sizeof *rows); 5837 rows = xmalloc (height * sizeof *rows);
5845 for (i = 0; i < height; ++i) 5838 for (i = 0; i < height; ++i)
5846 rows[i] = pixels + i * row_bytes; 5839 rows[i] = pixels + i * row_bytes;
5847 5840
@@ -6890,7 +6883,7 @@ tiff_load (struct frame *f, struct image *img)
6890 return 0; 6883 return 0;
6891 } 6884 }
6892 6885
6893 buf = (uint32 *) xmalloc (sizeof *buf * width * height); 6886 buf = xmalloc (sizeof *buf * width * height);
6894 6887
6895 rc = fn_TIFFReadRGBAImage (tiff, width, height, buf, 0); 6888 rc = fn_TIFFReadRGBAImage (tiff, width, height, buf, 0);
6896 6889