diff options
| author | Paul Eggert | 2016-12-01 00:17:20 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-12-01 00:19:06 -0800 |
| commit | fccd7d3c0606080c047e16d94490d83fc68dabde (patch) | |
| tree | 2ed9f725c3c5b49293e7dd357a1fa1f5019fe6cf | |
| parent | 319bafc9b28bd5bffb92a97a8ab53b9a3b97e6fd (diff) | |
| download | emacs-fccd7d3c0606080c047e16d94490d83fc68dabde.tar.gz emacs-fccd7d3c0606080c047e16d94490d83fc68dabde.zip | |
Make Cairo safer for --enable-gcc-warnings
* src/image.c (xcolor_to_argb32, pbm_load, jpeg_load_body, gif_load):
Avoid overflow warnings about ‘0xff << 24’.
(xpm_load, gif_load): Avoid unnecessary casts.
(gif_load): Fewer ifdefs.
| -rw-r--r-- | src/image.c | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/src/image.c b/src/image.c index 5614f39e15b..b5b713c9061 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -1096,8 +1096,8 @@ image_ascent (struct image *img, struct face *face, struct glyph_slice *slice) | |||
| 1096 | static uint32_t | 1096 | static uint32_t |
| 1097 | xcolor_to_argb32 (XColor xc) | 1097 | xcolor_to_argb32 (XColor xc) |
| 1098 | { | 1098 | { |
| 1099 | return (0xff << 24) | ((xc.red / 256) << 16) | 1099 | return ((0xffu << 24) | ((xc.red / 256) << 16) |
| 1100 | | ((xc.green / 256) << 8) | (xc.blue / 256); | 1100 | | ((xc.green / 256) << 8) | (xc.blue / 256)); |
| 1101 | } | 1101 | } |
| 1102 | 1102 | ||
| 1103 | static uint32_t | 1103 | static uint32_t |
| @@ -3726,10 +3726,10 @@ xpm_load (struct frame *f, struct image *img) | |||
| 3726 | { | 3726 | { |
| 3727 | int width = img->ximg->width; | 3727 | int width = img->ximg->width; |
| 3728 | int height = img->ximg->height; | 3728 | int height = img->ximg->height; |
| 3729 | unsigned char *data = (unsigned char *) xmalloc (width*height*4); | 3729 | void *data = xmalloc (width * height * 4); |
| 3730 | int i; | 3730 | int i; |
| 3731 | uint32_t *od = (uint32_t *)data; | 3731 | uint32_t *od = data; |
| 3732 | uint32_t *id = (uint32_t *)img->ximg->data; | 3732 | uint32_t *id = (uint32_t *) img->ximg->data; |
| 3733 | char *mid = img->mask_img ? img->mask_img->data : 0; | 3733 | char *mid = img->mask_img ? img->mask_img->data : 0; |
| 3734 | uint32_t bgcolor = get_spec_bg_or_alpha_as_argb (img, f); | 3734 | uint32_t bgcolor = get_spec_bg_or_alpha_as_argb (img, f); |
| 3735 | 3735 | ||
| @@ -5364,7 +5364,7 @@ pbm_load (struct frame *f, struct image *img) | |||
| 5364 | height = pbm_scan_number (&p, end); | 5364 | height = pbm_scan_number (&p, end); |
| 5365 | 5365 | ||
| 5366 | #ifdef USE_CAIRO | 5366 | #ifdef USE_CAIRO |
| 5367 | uint32_t *data = xmalloc (width * height * 4); | 5367 | void *data = xmalloc (width * height * 4); |
| 5368 | uint32_t *dataptr = data; | 5368 | uint32_t *dataptr = data; |
| 5369 | #endif | 5369 | #endif |
| 5370 | 5370 | ||
| @@ -5540,7 +5540,7 @@ pbm_load (struct frame *f, struct image *img) | |||
| 5540 | r = (double) r * 255 / max_color_idx; | 5540 | r = (double) r * 255 / max_color_idx; |
| 5541 | g = (double) g * 255 / max_color_idx; | 5541 | g = (double) g * 255 / max_color_idx; |
| 5542 | b = (double) b * 255 / max_color_idx; | 5542 | b = (double) b * 255 / max_color_idx; |
| 5543 | *dataptr++ = (0xff << 24) | (r << 16) | (g << 8) | b; | 5543 | *dataptr++ = (0xffu << 24) | (r << 16) | (g << 8) | b; |
| 5544 | #else | 5544 | #else |
| 5545 | /* RGB values are now in the range 0..max_color_idx. | 5545 | /* RGB values are now in the range 0..max_color_idx. |
| 5546 | Scale this to the range 0..0xffff supported by X. */ | 5546 | Scale this to the range 0..0xffff supported by X. */ |
| @@ -6835,7 +6835,7 @@ jpeg_load_body (struct frame *f, struct image *img, | |||
| 6835 | r = mgr->cinfo.colormap[ir][i]; | 6835 | r = mgr->cinfo.colormap[ir][i]; |
| 6836 | g = mgr->cinfo.colormap[ig][i]; | 6836 | g = mgr->cinfo.colormap[ig][i]; |
| 6837 | b = mgr->cinfo.colormap[ib][i]; | 6837 | b = mgr->cinfo.colormap[ib][i]; |
| 6838 | *dataptr++ = (0xff << 24) | (r << 16) | (g << 8) | b; | 6838 | *dataptr++ = (0xffu << 24) | (r << 16) | (g << 8) | b; |
| 6839 | } | 6839 | } |
| 6840 | } | 6840 | } |
| 6841 | 6841 | ||
| @@ -7628,14 +7628,6 @@ gif_load (struct frame *f, struct image *img) | |||
| 7628 | EMACS_INT idx; | 7628 | EMACS_INT idx; |
| 7629 | int gif_err; | 7629 | int gif_err; |
| 7630 | 7630 | ||
| 7631 | #ifdef USE_CAIRO | ||
| 7632 | unsigned char *data = 0; | ||
| 7633 | #else | ||
| 7634 | unsigned long pixel_colors[256]; | ||
| 7635 | unsigned long bgcolor = 0; | ||
| 7636 | XImagePtr ximg; | ||
| 7637 | #endif | ||
| 7638 | |||
| 7639 | if (NILP (specified_data)) | 7631 | if (NILP (specified_data)) |
| 7640 | { | 7632 | { |
| 7641 | Lisp_Object file = x_find_image_file (specified_file); | 7633 | Lisp_Object file = x_find_image_file (specified_file); |
| @@ -7766,24 +7758,26 @@ gif_load (struct frame *f, struct image *img) | |||
| 7766 | 7758 | ||
| 7767 | #ifdef USE_CAIRO | 7759 | #ifdef USE_CAIRO |
| 7768 | /* xzalloc so data is zero => transparent */ | 7760 | /* xzalloc so data is zero => transparent */ |
| 7769 | data = (unsigned char *) xzalloc (width * height * 4); | 7761 | void *data = xzalloc (width * height * 4); |
| 7762 | uint32_t *data32 = data; | ||
| 7770 | if (STRINGP (specified_bg)) | 7763 | if (STRINGP (specified_bg)) |
| 7771 | { | 7764 | { |
| 7772 | XColor color; | 7765 | XColor color; |
| 7773 | if (x_defined_color (f, SSDATA (specified_bg), &color, 0)) | 7766 | if (x_defined_color (f, SSDATA (specified_bg), &color, 0)) |
| 7774 | { | 7767 | { |
| 7775 | uint32_t *dataptr = (uint32_t *)data; | 7768 | uint32_t *dataptr = data32; |
| 7776 | int r = color.red/256; | 7769 | int r = color.red/256; |
| 7777 | int g = color.green/256; | 7770 | int g = color.green/256; |
| 7778 | int b = color.blue/256; | 7771 | int b = color.blue/256; |
| 7779 | 7772 | ||
| 7780 | for (y = 0; y < height; ++y) | 7773 | for (y = 0; y < height; ++y) |
| 7781 | for (x = 0; x < width; ++x) | 7774 | for (x = 0; x < width; ++x) |
| 7782 | *dataptr++ = (0xff << 24) | (r << 16) | (g << 8) | b; | 7775 | *dataptr++ = (0xffu << 24) | (r << 16) | (g << 8) | b; |
| 7783 | } | 7776 | } |
| 7784 | } | 7777 | } |
| 7785 | #else | 7778 | #else |
| 7786 | /* Create the X image and pixmap. */ | 7779 | /* Create the X image and pixmap. */ |
| 7780 | XImagePtr ximg; | ||
| 7787 | if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) | 7781 | if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0)) |
| 7788 | { | 7782 | { |
| 7789 | gif_close (gif, NULL); | 7783 | gif_close (gif, NULL); |
| @@ -7821,6 +7815,7 @@ gif_load (struct frame *f, struct image *img) | |||
| 7821 | init_color_table (); | 7815 | init_color_table (); |
| 7822 | 7816 | ||
| 7823 | #ifndef USE_CAIRO | 7817 | #ifndef USE_CAIRO |
| 7818 | unsigned long bgcolor; | ||
| 7824 | if (STRINGP (specified_bg)) | 7819 | if (STRINGP (specified_bg)) |
| 7825 | bgcolor = x_alloc_image_color (f, img, specified_bg, | 7820 | bgcolor = x_alloc_image_color (f, img, specified_bg, |
| 7826 | FRAME_BACKGROUND_PIXEL (f)); | 7821 | FRAME_BACKGROUND_PIXEL (f)); |
| @@ -7874,7 +7869,7 @@ gif_load (struct frame *f, struct image *img) | |||
| 7874 | 7869 | ||
| 7875 | #ifndef USE_CAIRO | 7870 | #ifndef USE_CAIRO |
| 7876 | /* Allocate subimage colors. */ | 7871 | /* Allocate subimage colors. */ |
| 7877 | memset (pixel_colors, 0, sizeof pixel_colors); | 7872 | unsigned long pixel_colors[256] = { 0, }; |
| 7878 | 7873 | ||
| 7879 | if (gif_color_map) | 7874 | if (gif_color_map) |
| 7880 | for (i = 0; i < gif_color_map->ColorCount; ++i) | 7875 | for (i = 0; i < gif_color_map->ColorCount; ++i) |
| @@ -7911,14 +7906,14 @@ gif_load (struct frame *f, struct image *img) | |||
| 7911 | { | 7906 | { |
| 7912 | #ifdef USE_CAIRO | 7907 | #ifdef USE_CAIRO |
| 7913 | uint32_t *dataptr = | 7908 | uint32_t *dataptr = |
| 7914 | ((uint32_t*)data + ((row + subimg_top) * subimg_width | 7909 | (data32 + ((row + subimg_top) * subimg_width |
| 7915 | + x + subimg_left)); | 7910 | + x + subimg_left)); |
| 7916 | int r = gif_color_map->Colors[c].Red; | 7911 | int r = gif_color_map->Colors[c].Red; |
| 7917 | int g = gif_color_map->Colors[c].Green; | 7912 | int g = gif_color_map->Colors[c].Green; |
| 7918 | int b = gif_color_map->Colors[c].Blue; | 7913 | int b = gif_color_map->Colors[c].Blue; |
| 7919 | 7914 | ||
| 7920 | if (transparency_color_index != c) | 7915 | if (transparency_color_index != c) |
| 7921 | *dataptr = (0xff << 24) | (r << 16) | (g << 8) | b; | 7916 | *dataptr = (0xffu << 24) | (r << 16) | (g << 8) | b; |
| 7922 | #else | 7917 | #else |
| 7923 | XPutPixel (ximg, x + subimg_left, row + subimg_top, | 7918 | XPutPixel (ximg, x + subimg_left, row + subimg_top, |
| 7924 | pixel_colors[c]); | 7919 | pixel_colors[c]); |
| @@ -7937,13 +7932,13 @@ gif_load (struct frame *f, struct image *img) | |||
| 7937 | { | 7932 | { |
| 7938 | #ifdef USE_CAIRO | 7933 | #ifdef USE_CAIRO |
| 7939 | uint32_t *dataptr = | 7934 | uint32_t *dataptr = |
| 7940 | ((uint32_t*)data + ((y + subimg_top) * subimg_width | 7935 | (data32 + ((y + subimg_top) * subimg_width |
| 7941 | + x + subimg_left)); | 7936 | + x + subimg_left)); |
| 7942 | int r = gif_color_map->Colors[c].Red; | 7937 | int r = gif_color_map->Colors[c].Red; |
| 7943 | int g = gif_color_map->Colors[c].Green; | 7938 | int g = gif_color_map->Colors[c].Green; |
| 7944 | int b = gif_color_map->Colors[c].Blue; | 7939 | int b = gif_color_map->Colors[c].Blue; |
| 7945 | if (transparency_color_index != c) | 7940 | if (transparency_color_index != c) |
| 7946 | *dataptr = (0xff << 24) | (r << 16) | (g << 8) | b; | 7941 | *dataptr = (0xffu << 24) | (r << 16) | (g << 8) | b; |
| 7947 | #else | 7942 | #else |
| 7948 | XPutPixel (ximg, x + subimg_left, y + subimg_top, | 7943 | XPutPixel (ximg, x + subimg_left, y + subimg_top, |
| 7949 | pixel_colors[c]); | 7944 | pixel_colors[c]); |