1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-10 05:30:45 -08:00

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.
This commit is contained in:
Paul Eggert 2016-12-01 00:17:20 -08:00
parent 319bafc9b2
commit fccd7d3c06

View file

@ -1096,8 +1096,8 @@ image_ascent (struct image *img, struct face *face, struct glyph_slice *slice)
static uint32_t
xcolor_to_argb32 (XColor xc)
{
return (0xff << 24) | ((xc.red / 256) << 16)
| ((xc.green / 256) << 8) | (xc.blue / 256);
return ((0xffu << 24) | ((xc.red / 256) << 16)
| ((xc.green / 256) << 8) | (xc.blue / 256));
}
static uint32_t
@ -3726,10 +3726,10 @@ xpm_load (struct frame *f, struct image *img)
{
int width = img->ximg->width;
int height = img->ximg->height;
unsigned char *data = (unsigned char *) xmalloc (width*height*4);
void *data = xmalloc (width * height * 4);
int i;
uint32_t *od = (uint32_t *)data;
uint32_t *id = (uint32_t *)img->ximg->data;
uint32_t *od = data;
uint32_t *id = (uint32_t *) img->ximg->data;
char *mid = img->mask_img ? img->mask_img->data : 0;
uint32_t bgcolor = get_spec_bg_or_alpha_as_argb (img, f);
@ -5364,7 +5364,7 @@ pbm_load (struct frame *f, struct image *img)
height = pbm_scan_number (&p, end);
#ifdef USE_CAIRO
uint32_t *data = xmalloc (width * height * 4);
void *data = xmalloc (width * height * 4);
uint32_t *dataptr = data;
#endif
@ -5540,7 +5540,7 @@ pbm_load (struct frame *f, struct image *img)
r = (double) r * 255 / max_color_idx;
g = (double) g * 255 / max_color_idx;
b = (double) b * 255 / max_color_idx;
*dataptr++ = (0xff << 24) | (r << 16) | (g << 8) | b;
*dataptr++ = (0xffu << 24) | (r << 16) | (g << 8) | b;
#else
/* RGB values are now in the range 0..max_color_idx.
Scale this to the range 0..0xffff supported by X. */
@ -6835,7 +6835,7 @@ jpeg_load_body (struct frame *f, struct image *img,
r = mgr->cinfo.colormap[ir][i];
g = mgr->cinfo.colormap[ig][i];
b = mgr->cinfo.colormap[ib][i];
*dataptr++ = (0xff << 24) | (r << 16) | (g << 8) | b;
*dataptr++ = (0xffu << 24) | (r << 16) | (g << 8) | b;
}
}
@ -7628,14 +7628,6 @@ gif_load (struct frame *f, struct image *img)
EMACS_INT idx;
int gif_err;
#ifdef USE_CAIRO
unsigned char *data = 0;
#else
unsigned long pixel_colors[256];
unsigned long bgcolor = 0;
XImagePtr ximg;
#endif
if (NILP (specified_data))
{
Lisp_Object file = x_find_image_file (specified_file);
@ -7766,24 +7758,26 @@ gif_load (struct frame *f, struct image *img)
#ifdef USE_CAIRO
/* xzalloc so data is zero => transparent */
data = (unsigned char *) xzalloc (width * height * 4);
void *data = xzalloc (width * height * 4);
uint32_t *data32 = data;
if (STRINGP (specified_bg))
{
XColor color;
if (x_defined_color (f, SSDATA (specified_bg), &color, 0))
{
uint32_t *dataptr = (uint32_t *)data;
uint32_t *dataptr = data32;
int r = color.red/256;
int g = color.green/256;
int b = color.blue/256;
for (y = 0; y < height; ++y)
for (x = 0; x < width; ++x)
*dataptr++ = (0xff << 24) | (r << 16) | (g << 8) | b;
*dataptr++ = (0xffu << 24) | (r << 16) | (g << 8) | b;
}
}
#else
/* Create the X image and pixmap. */
XImagePtr ximg;
if (!image_create_x_image_and_pixmap (f, img, width, height, 0, &ximg, 0))
{
gif_close (gif, NULL);
@ -7821,6 +7815,7 @@ gif_load (struct frame *f, struct image *img)
init_color_table ();
#ifndef USE_CAIRO
unsigned long bgcolor;
if (STRINGP (specified_bg))
bgcolor = x_alloc_image_color (f, img, specified_bg,
FRAME_BACKGROUND_PIXEL (f));
@ -7874,7 +7869,7 @@ gif_load (struct frame *f, struct image *img)
#ifndef USE_CAIRO
/* Allocate subimage colors. */
memset (pixel_colors, 0, sizeof pixel_colors);
unsigned long pixel_colors[256] = { 0, };
if (gif_color_map)
for (i = 0; i < gif_color_map->ColorCount; ++i)
@ -7911,14 +7906,14 @@ gif_load (struct frame *f, struct image *img)
{
#ifdef USE_CAIRO
uint32_t *dataptr =
((uint32_t*)data + ((row + subimg_top) * subimg_width
+ x + subimg_left));
(data32 + ((row + subimg_top) * subimg_width
+ x + subimg_left));
int r = gif_color_map->Colors[c].Red;
int g = gif_color_map->Colors[c].Green;
int b = gif_color_map->Colors[c].Blue;
if (transparency_color_index != c)
*dataptr = (0xff << 24) | (r << 16) | (g << 8) | b;
*dataptr = (0xffu << 24) | (r << 16) | (g << 8) | b;
#else
XPutPixel (ximg, x + subimg_left, row + subimg_top,
pixel_colors[c]);
@ -7937,13 +7932,13 @@ gif_load (struct frame *f, struct image *img)
{
#ifdef USE_CAIRO
uint32_t *dataptr =
((uint32_t*)data + ((y + subimg_top) * subimg_width
+ x + subimg_left));
(data32 + ((y + subimg_top) * subimg_width
+ x + subimg_left));
int r = gif_color_map->Colors[c].Red;
int g = gif_color_map->Colors[c].Green;
int b = gif_color_map->Colors[c].Blue;
if (transparency_color_index != c)
*dataptr = (0xff << 24) | (r << 16) | (g << 8) | b;
*dataptr = (0xffu << 24) | (r << 16) | (g << 8) | b;
#else
XPutPixel (ximg, x + subimg_left, y + subimg_top,
pixel_colors[c]);