if (ncolors >= SIZE_MAX / sizeof(XColor) || cpp >= SIZE_MAX - 1)
if (ncolors >= UINT_MAX / sizeof(XColor) || cpp >= UINT_MAX - 1)
ScanOtherColors(display, colors, ncolors, pixels, mask, cpp, attributes)    Display *display;    XpmColor *colors;    unsigned int ncolors;    Pixel *pixels;    unsigned int mask;    unsigned int cpp;    XpmAttributes *attributes;{    /* variables stored in the XpmAttributes structure */    Colormap colormap;    char *rgb_fname;#ifndef FOR_MSW    xpmRgbName rgbn[MAX_RGBNAMES];#else    xpmRgbName *rgbn = NULL; #endif        int rgbn_max = 0;    unsigned int i, j, c, i2;    XpmColor *color;    XColor *xcolors = NULL, *xcolor;    char *colorname, *s;    XpmColor *colorTable = NULL, **oldColorTable = NULL;    unsigned int ancolors = 0;    Pixel *apixels = NULL;    unsigned int mask_pixel = 0;    Bool found;    /* retrieve information from the XpmAttributes */    if (attributes && (attributes->valuemask & XpmColormap))	colormap = attributes->colormap;    else	colormap = XDefaultColormap(display, XDefaultScreen(display));    if (attributes && (attributes->valuemask & XpmRgbFilename))	rgb_fname = attributes->rgb_fname;    else	rgb_fname = NULL;    /* start from the right element */    if (mask) {	colors++;	ncolors--;	pixels++;    }    /* first get character strings and rgb values */    if (ncolors >= SIZE_MAX / sizeof(XColor) || cpp >= SIZE_MAX - 1)	return (XpmNoMemory);    xcolors = (XColor *) XpmMalloc(sizeof(XColor) * ncolors);    if (!xcolors)	return (XpmNoMemory);    for (i = 0, i2 = mask, color = colors, xcolor = xcolors;	 i < ncolors; i++, i2++, color++, xcolor++, pixels++) {	if (!(s = color->string = (char *) XpmMalloc(cpp + 1))) {	    XpmFree(xcolors);	    return (XpmNoMemory);	}	*s++ = printable[c = i2 % MAXPRINTABLE];	for (j = 1; j < cpp; j++, s++)	    *s = printable[c = ((i2 - c) / MAXPRINTABLE) % MAXPRINTABLE];	*s = '\0';	xcolor->pixel = *pixels;    }    XQueryColors(display, colormap, xcolors, ncolors);#ifndef FOR_MSW    /* read the rgb file if any was specified */    if (rgb_fname)	rgbn_max = xpmReadRgbNames(attributes->rgb_fname, rgbn);#else    /* FOR_MSW: rgb names and values are hardcoded in rgbtab.h */    rgbn_max = xpmReadRgbNames(NULL, NULL);#endif    if (attributes && attributes->valuemask & XpmColorTable) {	colorTable = attributes->colorTable;	ancolors = attributes->ncolors;	apixels = attributes->pixels;	mask_pixel = attributes->mask_pixel;    }/* 3.2 backward compatibility code */    else if (attributes && attributes->valuemask & XpmInfos) {	oldColorTable = (XpmColor **) attributes->colorTable;	ancolors = attributes->ncolors;	apixels = attributes->pixels;	mask_pixel = attributes->mask_pixel;    }/* end 3.2 bc */    for (i = 0, color = colors, xcolor = xcolors; i < ncolors;						  i++, color++, xcolor++) {	/* look for related info from the attributes if any */	found = False;	if (ancolors) {	    unsigned int offset = 0;	    for (j = 0; j < ancolors; j++) {		if (j == mask_pixel) {		    offset = 1;		    continue;		}		if (apixels[j - offset] == xcolor->pixel)		    break;	    }	    if (j != ancolors) {		unsigned int key;		char **defaults = (char **) color;		char **adefaults;/* 3.2 backward compatibility code */		if (oldColorTable)		    adefaults = (char **) oldColorTable[j];		else/* end 3.2 bc */		    adefaults = (char **) (colorTable + j);		found = True;		for (key = 1; key <= NKEYS; key++) {		    if ((s = adefaults[key]))			defaults[key] = (char *) xpmstrdup(s);		}	    }	}	if (!found) {	    /* if nothing found look for a color name */	    colorname = NULL;	    if (rgbn_max)		colorname = xpmGetRgbName(rgbn, rgbn_max, xcolor->red,					  xcolor->green, xcolor->blue);	    if (colorname)		color->c_color = (char *) xpmstrdup(colorname);	    else {		/* at last store the rgb value */		char buf[BUFSIZ];#ifndef FOR_MSW		sprintf(buf, "#%04X%04X%04X",			xcolor->red, xcolor->green, xcolor->blue);#else   		sprintf(buf, "#%02x%02x%02x",			xcolor->red, xcolor->green, xcolor->blue);#endif					color->c_color = (char *) xpmstrdup(buf);	    }	    if (!color->c_color) {		XpmFree(xcolors);		xpmFreeRgbNames(rgbn, rgbn_max);		return (XpmNoMemory);	    }	}    }    XpmFree(xcolors);    xpmFreeRgbNames(rgbn, rgbn_max);    return (XpmSuccess);}