Fix tests for maximum number of colours when creating a colourmap, so a
32-bit visual (e.g. ARGB) doesn't overflow an int when attempting to do 1 << 32. (Benjamin Herrenschmidt)
This commit is contained in:
		
							parent
							
								
									5c5c51fa6d
								
							
						
					
					
						commit
						c8de8c23fb
					
				| 
						 | 
					@ -245,6 +245,14 @@ CMapCloseScreen (int i, ScreenPtr pScreen)
 | 
				
			||||||
    return (*pScreen->CloseScreen) (i, pScreen);
 | 
					    return (*pScreen->CloseScreen) (i, pScreen);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static Bool
 | 
				
			||||||
 | 
					CMapColormapUseMax(VisualPtr pVisual, CMapScreenPtr pScreenPriv)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (pVisual->nplanes > 16)
 | 
				
			||||||
 | 
					        return TRUE;
 | 
				
			||||||
 | 
					    return ((1 << pVisual->nplanes) > pScreenPriv->maxColors);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static Bool
 | 
					static Bool
 | 
				
			||||||
CMapAllocateColormapPrivate(ColormapPtr pmap)
 | 
					CMapAllocateColormapPrivate(ColormapPtr pmap)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -255,7 +263,7 @@ CMapAllocateColormapPrivate(ColormapPtr pmap)
 | 
				
			||||||
    int numColors;
 | 
					    int numColors;
 | 
				
			||||||
    LOCO *colors;
 | 
					    LOCO *colors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if((1 << pmap->pVisual->nplanes) > pScreenPriv->maxColors)
 | 
					    if (CMapColormapUseMax(pmap->pVisual, pScreenPriv))
 | 
				
			||||||
	numColors = pmap->pVisual->ColormapEntries;
 | 
						numColors = pmap->pVisual->ColormapEntries;
 | 
				
			||||||
    else 
 | 
					    else 
 | 
				
			||||||
	numColors = 1 << pmap->pVisual->nplanes; 
 | 
						numColors = 1 << pmap->pVisual->nplanes; 
 | 
				
			||||||
| 
						 | 
					@ -371,7 +379,7 @@ CMapStoreColors(
 | 
				
			||||||
	   (CMapColormapPtr) pmap->devPrivates[CMapColormapIndex].ptr;
 | 
						   (CMapColormapPtr) pmap->devPrivates[CMapColormapIndex].ptr;
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if((1 << pVisual->nplanes) > pScreenPriv->maxColors) {
 | 
						if (CMapColormapUseMax(pVisual, pScreenPriv)) {
 | 
				
			||||||
	    int index;
 | 
						    int index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    num = 0;
 | 
						    num = 0;
 | 
				
			||||||
| 
						 | 
					@ -440,10 +448,10 @@ CMapInstallColormap(ColormapPtr pmap)
 | 
				
			||||||
    if (miInstalledMaps[index])
 | 
					    if (miInstalledMaps[index])
 | 
				
			||||||
	pmap = miInstalledMaps[index];
 | 
						pmap = miInstalledMaps[index];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
 | 
					    if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
 | 
				
			||||||
	(pmap->pVisual->class == TrueColor) &&
 | 
						 (pmap->pVisual->class == TrueColor) &&
 | 
				
			||||||
	((1 << pmap->pVisual->nplanes) > pScreenPriv->maxColors))
 | 
						 CMapColormapUseMax(pmap->pVisual, pScreenPriv))
 | 
				
			||||||
		return;
 | 
						return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(LOAD_PALETTE(pmap, index))
 | 
					    if(LOAD_PALETTE(pmap, index))
 | 
				
			||||||
	CMapReinstallMap(pmap);
 | 
						CMapReinstallMap(pmap);
 | 
				
			||||||
| 
						 | 
					@ -572,7 +580,7 @@ CMapRefreshColors(ColormapPtr pmap, int defs, int* indices)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	break;
 | 
						break;
 | 
				
			||||||
    case TrueColor:
 | 
					    case TrueColor:
 | 
				
			||||||
	if((1 << pVisual->nplanes) > pScreenPriv->maxColors) {
 | 
					        if (CMapColormapUseMax(pVisual, pScreenPriv)) {
 | 
				
			||||||
	    for(i = 0; i <= reds; i++) 
 | 
						    for(i = 0; i <= reds; i++) 
 | 
				
			||||||
		colors[i].red   = gamma[i * maxValue / reds].red;
 | 
							colors[i].red   = gamma[i * maxValue / reds].red;
 | 
				
			||||||
	    for(i = 0; i <= greens; i++) 
 | 
						    for(i = 0; i <= greens; i++) 
 | 
				
			||||||
| 
						 | 
					@ -615,7 +623,7 @@ CMapRefreshColors(ColormapPtr pmap, int defs, int* indices)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	break;
 | 
						break;
 | 
				
			||||||
    case DirectColor:
 | 
					    case DirectColor:
 | 
				
			||||||
	if((1 << pVisual->nplanes) > pScreenPriv->maxColors) {
 | 
					        if (CMapColormapUseMax(pVisual, pScreenPriv)) {
 | 
				
			||||||
	    for(i = 0; i < defs; i++) { 
 | 
						    for(i = 0; i < defs; i++) { 
 | 
				
			||||||
		index = indices[i];
 | 
							index = indices[i];
 | 
				
			||||||
		if(index <= reds)
 | 
							if(index <= reds)
 | 
				
			||||||
| 
						 | 
					@ -930,9 +938,9 @@ CMapChangeGamma(
 | 
				
			||||||
	pScrn->vtSema || pScreenPriv->isDGAmode)) {
 | 
						pScrn->vtSema || pScreenPriv->isDGAmode)) {
 | 
				
			||||||
	ColormapPtr pMap = miInstalledMaps[pScreen->myNum];
 | 
						ColormapPtr pMap = miInstalledMaps[pScreen->myNum];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
 | 
						if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
 | 
				
			||||||
	    (pMap->pVisual->class == TrueColor) &&
 | 
						    (pMap->pVisual->class == TrueColor) &&
 | 
				
			||||||
	    ((1 << pMap->pVisual->nplanes) > pScreenPriv->maxColors)) {
 | 
						    CMapColormapUseMax(pMap->pVisual, pScreenPriv)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    /* if the current map doesn't have a palette look
 | 
						    /* if the current map doesn't have a palette look
 | 
				
			||||||
		for another map to change the gamma on. */
 | 
							for another map to change the gamma on. */
 | 
				
			||||||
| 
						 | 
					@ -1017,9 +1025,9 @@ xf86ChangeGammaRamp(
 | 
				
			||||||
        pScrn->vtSema || pScreenPriv->isDGAmode)) {
 | 
					        pScrn->vtSema || pScreenPriv->isDGAmode)) {
 | 
				
			||||||
        ColormapPtr pMap = miInstalledMaps[pScreen->myNum];
 | 
					        ColormapPtr pMap = miInstalledMaps[pScreen->myNum];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
 | 
					        if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
 | 
				
			||||||
            (pMap->pVisual->class == TrueColor) &&
 | 
					            (pMap->pVisual->class == TrueColor) &&
 | 
				
			||||||
            ((1 << pMap->pVisual->nplanes) > pScreenPriv->maxColors)) {
 | 
						    CMapColormapUseMax(pMap->pVisual, pScreenPriv)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* if the current map doesn't have a palette look
 | 
					            /* if the current map doesn't have a palette look
 | 
				
			||||||
                for another map to change the gamma on. */
 | 
					                for another map to change the gamma on. */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue