aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
authorPaul Eggert2012-07-05 11:35:48 -0700
committerPaul Eggert2012-07-05 11:35:48 -0700
commit38182d901d030c7d65f4aa7a49b583afb30eb9b7 (patch)
treea69e1a571495d6ca1c034359d7c995639774ab9b /src/image.c
parent6dd5a677dbf794eedaa8325c46d57ac041373361 (diff)
downloademacs-38182d901d030c7d65f4aa7a49b583afb30eb9b7.tar.gz
emacs-38182d901d030c7d65f4aa7a49b583afb30eb9b7.zip
More xmalloc and related cleanup.
* alloc.c, bidi.c, buffer.c, buffer.h, bytecode.c, callint.c: * callproc.c, charset.c, coding.c, composite.c, data.c, dispnew.c: * doc.c, editfns.c, emacs.c, eval.c, fileio.c, filelock.c, fns.c: * font.c, fontset.c, frame.c, fringe.c, ftfont.c, ftxfont.c, gmalloc.c: * gtkutil.c, image.c, keyboard.c, keymap.c, lread.c, macros.c, menu.c: * nsfns.m, nsfont.m, nsmenu.m, nsterm.m, print.c, process.c, ralloc.c: * regex.c, region-cache.c, scroll.c, search.c, sound.c, syntax.c: * sysdep.c, term.c, termcap.c, unexmacosx.c, window.c, xdisp.c: * xfaces.c, xfns.c, xftfont.c, xgselect.c, xmenu.c, xrdb.c, xselect.c: * xterm.c: Omit needless casts involving void * pointers and allocation. Prefer "P = xmalloc (sizeof *P)" to "P = xmalloc (sizeof (TYPE_OF_P))", as the former is more robust if P's type is changed. Prefer xzalloc to xmalloc + memset 0. Simplify malloc-or-realloc to realloc. Don't worry about xmalloc returning a null pointer. Prefer xstrdup to xmalloc + strcpy. * editfns.c (Fmessage_box): Grow message_text by at least 80 when growing it. * keyboard.c (apply_modifiers_uncached): Prefer local array to alloca of a constant.
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/image.c b/src/image.c
index 45dcb554439..4877d262d00 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1356,9 +1356,7 @@ x_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_name,
1356 /* This isn't called frequently so we get away with simply 1356 /* This isn't called frequently so we get away with simply
1357 reallocating the color vector to the needed size, here. */ 1357 reallocating the color vector to the needed size, here. */
1358 ptrdiff_t ncolors = img->ncolors + 1; 1358 ptrdiff_t ncolors = img->ncolors + 1;
1359 img->colors = 1359 img->colors = xrealloc (img->colors, ncolors * sizeof *img->colors);
1360 (unsigned long *) xrealloc (img->colors,
1361 ncolors * sizeof *img->colors);
1362 img->colors[ncolors - 1] = color.pixel; 1360 img->colors[ncolors - 1] = color.pixel;
1363 img->ncolors = ncolors; 1361 img->ncolors = ncolors;
1364 result = color.pixel; 1362 result = color.pixel;
@@ -2500,7 +2498,7 @@ w32_create_pixmap_from_bitmap_data (int width, int height, char *data)
2500 2498
2501 w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */ 2499 w1 = (width + 7) / 8; /* nb of 8bits elt in X bitmap */
2502 w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */ 2500 w2 = ((width + 15) / 16) * 2; /* nb of 16bits elt in W32 bitmap */
2503 bits = (unsigned char *) alloca (height * w2); 2501 bits = alloca (height * w2);
2504 memset (bits, 0, height * w2); 2502 memset (bits, 0, height * w2);
2505 for (i = 0; i < height; i++) 2503 for (i = 0; i < height; i++)
2506 { 2504 {
@@ -2927,7 +2925,7 @@ xbm_load (struct frame *f, struct image *img)
2927 char *p; 2925 char *p;
2928 int nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR; 2926 int nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR;
2929 2927
2930 p = bits = (char *) alloca (nbytes * img->height); 2928 p = bits = alloca (nbytes * img->height);
2931 for (i = 0; i < img->height; ++i, p += nbytes) 2929 for (i = 0; i < img->height; ++i, p += nbytes)
2932 { 2930 {
2933 Lisp_Object line = AREF (data, i); 2931 Lisp_Object line = AREF (data, i);
@@ -2950,7 +2948,7 @@ xbm_load (struct frame *f, struct image *img)
2950 invertedBits = bits; 2948 invertedBits = bits;
2951 nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR 2949 nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR
2952 * img->height; 2950 * img->height;
2953 bits = (char *) alloca (nbytes); 2951 bits = alloca (nbytes);
2954 for (i = 0; i < nbytes; i++) 2952 for (i = 0; i < nbytes; i++)
2955 bits[i] = XBM_BIT_SHUFFLE (invertedBits[i]); 2953 bits[i] = XBM_BIT_SHUFFLE (invertedBits[i]);
2956 } 2954 }
@@ -3422,7 +3420,7 @@ xpm_load (struct frame *f, struct image *img)
3422 3420
3423 /* Allocate an XpmColorSymbol array. */ 3421 /* Allocate an XpmColorSymbol array. */
3424 size = attrs.numsymbols * sizeof *xpm_syms; 3422 size = attrs.numsymbols * sizeof *xpm_syms;
3425 xpm_syms = (XpmColorSymbol *) alloca (size); 3423 xpm_syms = alloca (size);
3426 memset (xpm_syms, 0, size); 3424 memset (xpm_syms, 0, size);
3427 attrs.colorsymbols = xpm_syms; 3425 attrs.colorsymbols = xpm_syms;
3428 3426
@@ -3445,14 +3443,14 @@ xpm_load (struct frame *f, struct image *img)
3445 color = XCDR (XCAR (tail)); 3443 color = XCDR (XCAR (tail));
3446 if (STRINGP (name)) 3444 if (STRINGP (name))
3447 { 3445 {
3448 xpm_syms[i].name = (char *) alloca (SCHARS (name) + 1); 3446 xpm_syms[i].name = alloca (SCHARS (name) + 1);
3449 strcpy (xpm_syms[i].name, SSDATA (name)); 3447 strcpy (xpm_syms[i].name, SSDATA (name));
3450 } 3448 }
3451 else 3449 else
3452 xpm_syms[i].name = empty_string; 3450 xpm_syms[i].name = empty_string;
3453 if (STRINGP (color)) 3451 if (STRINGP (color))
3454 { 3452 {
3455 xpm_syms[i].value = (char *) alloca (SCHARS (color) + 1); 3453 xpm_syms[i].value = alloca (SCHARS (color) + 1);
3456 strcpy (xpm_syms[i].value, SSDATA (color)); 3454 strcpy (xpm_syms[i].value, SSDATA (color));
3457 } 3455 }
3458 else 3456 else
@@ -6449,8 +6447,7 @@ jpeg_load (struct frame *f, struct image *img)
6449 a default color, and we don't have to care about which colors 6447 a default color, and we don't have to care about which colors
6450 can be freed safely, and which can't. */ 6448 can be freed safely, and which can't. */
6451 init_color_table (); 6449 init_color_table ();
6452 colors = (unsigned long *) alloca (cinfo.actual_number_of_colors 6450 colors = alloca (cinfo.actual_number_of_colors * sizeof *colors);
6453 * sizeof *colors);
6454 6451
6455 for (i = 0; i < cinfo.actual_number_of_colors; ++i) 6452 for (i = 0; i < cinfo.actual_number_of_colors; ++i)
6456 { 6453 {