if (image->ncolors >= SIZE_MAX / sizeof(Pixel)) return (XpmNoMemory);
XpmCreateImageFromXpmImage(display, image,			   image_return, shapeimage_return, attributes)    Display *display;    XpmImage *image;    XImage **image_return;    XImage **shapeimage_return;    XpmAttributes *attributes;{    /* variables stored in the XpmAttributes structure */    Visual *visual;    Colormap colormap;    unsigned int depth;    int bitmap_format;    XpmFreeColorsFunc freeColors;    /* variables to return */    XImage *ximage = NULL;    XImage *shapeimage = NULL;    unsigned int mask_pixel_index = XpmUndefPixel;    int ErrorStatus;    /* calculation variables */    Pixel *image_pixels = NULL;    Pixel *mask_pixels = NULL;    Pixel *alloc_pixels = NULL;    Pixel *used_pixels = NULL;    unsigned int nalloc_pixels = 0;    unsigned int nused_pixels = 0;    /* initialize return values */    if (image_return)	*image_return = NULL;    if (shapeimage_return)	*shapeimage_return = NULL;    /* retrieve information from the XpmAttributes */    if (attributes && (attributes->valuemask & XpmVisual))	visual = attributes->visual;    else	visual = XDefaultVisual(display, XDefaultScreen(display));    if (attributes && (attributes->valuemask & XpmColormap))	colormap = attributes->colormap;    else	colormap = XDefaultColormap(display, XDefaultScreen(display));    if (attributes && (attributes->valuemask & XpmDepth))	depth = attributes->depth;    else	depth = XDefaultDepth(display, XDefaultScreen(display));    if (attributes && (attributes->valuemask & XpmBitmapFormat))	bitmap_format = attributes->bitmap_format;    else	bitmap_format = ZPixmap;    if (attributes && (attributes->valuemask & XpmFreeColors))	freeColors = attributes->free_colors;    else	freeColors = FreeColors;    ErrorStatus = XpmSuccess;    /* malloc pixels index tables */    image_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);    if (!image_pixels)	return (XpmNoMemory);    mask_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);    if (!mask_pixels)	RETURN(XpmNoMemory);    /* maximum of allocated pixels will be the number of colors */    alloc_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);    if (!alloc_pixels)	RETURN(XpmNoMemory);    /* maximum of allocated pixels will be the number of colors */    used_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * image->ncolors);    if (!used_pixels)	RETURN(XpmNoMemory);    /* get pixel colors, store them in index tables */    ErrorStatus = CreateColors(display, attributes, image->colorTable,			       image->ncolors, image_pixels, mask_pixels,			       &mask_pixel_index, alloc_pixels, &nalloc_pixels,			       used_pixels, &nused_pixels);    if (ErrorStatus != XpmSuccess	&& (ErrorStatus < 0 || (attributes				&& (attributes->valuemask & XpmExactColors)				&& attributes->exactColors)))	RETURN(ErrorStatus);    /* create the ximage */    if (image_return) {	ErrorStatus = CreateXImage(display, visual, depth,				   (depth == 1 ? bitmap_format : ZPixmap),				   image->width, image->height, &ximage);	if (ErrorStatus != XpmSuccess)	    RETURN(ErrorStatus);#ifndef FOR_MSW# ifndef AMIGA	/*	 * set the ximage data using optimized functions for ZPixmap	 */	if (ximage->bits_per_pixel == 8)	    PutImagePixels8(ximage, image->width, image->height,			    image->data, image_pixels);	else if (((ximage->bits_per_pixel | ximage->depth) == 1) &&		 (ximage->byte_order == ximage->bitmap_bit_order))	    PutImagePixels1(ximage, image->width, image->height,			    image->data, image_pixels);	else if (ximage->bits_per_pixel == 16)	    PutImagePixels16(ximage, image->width, image->height,			     image->data, image_pixels);	else if (ximage->bits_per_pixel == 32)	    PutImagePixels32(ximage, image->width, image->height,			     image->data, image_pixels);	else	    PutImagePixels(ximage, image->width, image->height,			   image->data, image_pixels);# else /* AMIGA */	APutImagePixels(ximage, image->width, image->height,			image->data, image_pixels);# endif#else  /* FOR_MSW */	MSWPutImagePixels(display, ximage, image->width, image->height,			  image->data, image_pixels);#endif    }    /* create the shape mask image */    if (mask_pixel_index != XpmUndefPixel && shapeimage_return) {	ErrorStatus = CreateXImage(display, visual, 1, bitmap_format,				   image->width, image->height, &shapeimage);	if (ErrorStatus != XpmSuccess)	    RETURN(ErrorStatus);#ifndef FOR_MSW# ifndef AMIGA	PutImagePixels1(shapeimage, image->width, image->height,			image->data, mask_pixels);# else /* AMIGA */	APutImagePixels(shapeimage, image->width, image->height,			image->data, mask_pixels);# endif#else  /* FOR_MSW */	MSWPutImagePixels(display, shapeimage, image->width, image->height,			  image->data, mask_pixels);#endif    }    XpmFree(image_pixels);    XpmFree(mask_pixels);    /* if requested return used pixels in the XpmAttributes structure */    if (attributes && (attributes->valuemask & XpmReturnPixels ||/* 3.2 backward compatibility code */	attributes->valuemask & XpmReturnInfos)) {/* end 3.2 bc */	attributes->pixels = used_pixels;	attributes->npixels = nused_pixels;	attributes->mask_pixel = mask_pixel_index;    } else	XpmFree(used_pixels);    /* if requested return alloc'ed pixels in the XpmAttributes structure */    if (attributes && (attributes->valuemask & XpmReturnAllocPixels)) {	attributes->alloc_pixels = alloc_pixels;	attributes->nalloc_pixels = nalloc_pixels;    } else	XpmFree(alloc_pixels);    /* return created images */    if (image_return)	*image_return = ximage;    if (shapeimage_return)	*shapeimage_return = shapeimage;    return (ErrorStatus);/* exit point in case of error, free only locally allocated variables */error:    if (ximage)	XDestroyImage(ximage);    if (shapeimage)	XDestroyImage(shapeimage);    if (image_pixels)	XpmFree(image_pixels);    if (mask_pixels)	XpmFree(mask_pixels);    if (nalloc_pixels)	(*freeColors)(display, colormap, alloc_pixels, nalloc_pixels, NULL);    if (alloc_pixels)	XpmFree(alloc_pixels);    if (used_pixels)	XpmFree(used_pixels);    return (ErrorStatus);}