Avoid calling xalloc(0). Change rrScreenSizeSet to rrScreenSetSize.

This commit is contained in:
Keith Packard 2006-09-20 12:05:52 -07:00
parent ef1f3248cb
commit d08718d8fd
6 changed files with 98 additions and 43 deletions

View File

@ -198,7 +198,7 @@ Bool RRScreenInit(ScreenPtr pScreen)
pScrPriv->maxHeight = pScrPriv->minHeight = pScreen->height; pScrPriv->maxHeight = pScrPriv->minHeight = pScreen->height;
#if RANDR_12_INTERFACE #if RANDR_12_INTERFACE
pScrPriv->rrScreenSizeSet = NULL; pScrPriv->rrScreenSetSize = NULL;
pScrPriv->rrCrtcSet = NULL; pScrPriv->rrCrtcSet = NULL;
pScrPriv->rrCrtcSetGamma = NULL; pScrPriv->rrCrtcSetGamma = NULL;
#endif #endif

View File

@ -174,7 +174,7 @@ typedef struct _rrScrPriv {
#endif #endif
RRGetInfoProcPtr rrGetInfo; RRGetInfoProcPtr rrGetInfo;
#if RANDR_12_INTERFACE #if RANDR_12_INTERFACE
RRScreenSetSizeProcPtr rrScreenSizeSet; RRScreenSetSizeProcPtr rrScreenSetSize;
RRCrtcSetProcPtr rrCrtcSet; RRCrtcSetProcPtr rrCrtcSet;
RRCrtcSetGammaProcPtr rrCrtcSetGamma; RRCrtcSetGammaProcPtr rrCrtcSetGamma;
#endif #endif
@ -521,7 +521,7 @@ RRClientKnowsRates (ClientPtr pClient);
RRModePtr RRModePtr
RRModeGet (ScreenPtr pScreen, RRModeGet (ScreenPtr pScreen,
xRRModeInfo *modeInfo, xRRModeInfo *modeInfo,
char *name); const char *name);
/* /*
* Destroy a mode. * Destroy a mode.
@ -555,7 +555,7 @@ ProcRRDeleteOutputMode (ClientPtr client);
RROutputPtr RROutputPtr
RROutputCreate (ScreenPtr pScreen, RROutputCreate (ScreenPtr pScreen,
char *name, const char *name,
int nameLength, int nameLength,
void *devPrivate); void *devPrivate);

View File

@ -94,6 +94,8 @@ RRCrtcNotify (RRCrtcPtr crtc,
{ {
RROutputPtr *outputs; RROutputPtr *outputs;
if (numOutputs)
{
if (crtc->numOutputs) if (crtc->numOutputs)
outputs = xrealloc (crtc->outputs, outputs = xrealloc (crtc->outputs,
numOutputs * sizeof (RROutputPtr)); numOutputs * sizeof (RROutputPtr));
@ -101,6 +103,13 @@ RRCrtcNotify (RRCrtcPtr crtc,
outputs = xalloc (numOutputs * sizeof (RROutputPtr)); outputs = xalloc (numOutputs * sizeof (RROutputPtr));
if (!outputs) if (!outputs)
return FALSE; return FALSE;
}
else
{
if (crtc->outputs)
xfree (crtc->outputs);
outputs = NULL;
}
crtc->outputs = outputs; crtc->outputs = outputs;
} }
for (i = 0; i < numOutputs; i++) for (i = 0; i < numOutputs; i++)
@ -300,9 +309,14 @@ RRCrtcGammaSetSize (RRCrtcPtr crtc,
if (size == crtc->gammaSize) if (size == crtc->gammaSize)
return TRUE; return TRUE;
if (size)
{
gamma = xalloc (size * 3 * sizeof (CARD16)); gamma = xalloc (size * 3 * sizeof (CARD16));
if (!gamma) if (!gamma)
return FALSE; return FALSE;
}
else
gamma = NULL;
if (crtc->gammaRed) if (crtc->gammaRed)
xfree (crtc->gammaRed); xfree (crtc->gammaRed);
crtc->gammaRed = gamma; crtc->gammaRed = gamma;
@ -376,9 +390,14 @@ ProcRRGetCrtcInfo (ClientPtr client)
rep.length = rep.nOutput + rep.nPossibleOutput; rep.length = rep.nOutput + rep.nPossibleOutput;
extraLen = rep.length << 2; extraLen = rep.length << 2;
if (extraLen)
{
extra = xalloc (extraLen); extra = xalloc (extraLen);
if (!extra) if (!extra)
return BadAlloc; return BadAlloc;
}
else
extra = NULL;
outputs = (RROutput *) extra; outputs = (RROutput *) extra;
possible = (RROutput *) (outputs + rep.nOutput); possible = (RROutput *) (outputs + rep.nOutput);
@ -467,9 +486,14 @@ ProcRRSetCrtcConfig (ClientPtr client)
if (numOutputs == 0) if (numOutputs == 0)
return BadMatch; return BadMatch;
} }
if (numOutputs)
{
outputs = xalloc (numOutputs * sizeof (RROutputPtr)); outputs = xalloc (numOutputs * sizeof (RROutputPtr));
if (!outputs) if (!outputs)
return BadAlloc; return BadAlloc;
}
else
outputs = NULL;
outputIds = (RROutput *) (stuff + 1); outputIds = (RROutput *) (stuff + 1);
for (i = 0; i < numOutputs; i++) for (i = 0; i < numOutputs; i++)
@ -574,7 +598,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
* for setting screen size. Else, assume the CrtcSet sets * for setting screen size. Else, assume the CrtcSet sets
* the size along with the mode * the size along with the mode
*/ */
if (pScrPriv->rrScreenSizeSet) if (pScrPriv->rrScreenSetSize)
{ {
if (stuff->x + mode->mode.width > pScreen->width) if (stuff->x + mode->mode.width > pScreen->width)
{ {

View File

@ -27,7 +27,7 @@ RESTYPE RRModeType;
RRModePtr RRModePtr
RRModeGet (ScreenPtr pScreen, RRModeGet (ScreenPtr pScreen,
xRRModeInfo *modeInfo, xRRModeInfo *modeInfo,
char *name) const char *name)
{ {
rrScrPriv (pScreen); rrScrPriv (pScreen);
int i; int i;

View File

@ -30,7 +30,7 @@ RESTYPE RROutputType;
RROutputPtr RROutputPtr
RROutputCreate (ScreenPtr pScreen, RROutputCreate (ScreenPtr pScreen,
char *name, const char *name,
int nameLength, int nameLength,
void *devPrivate) void *devPrivate)
{ {
@ -89,9 +89,14 @@ RROutputSetClones (RROutputPtr output,
{ {
RROutputPtr *newClones; RROutputPtr *newClones;
if (numClones)
{
newClones = xalloc (numClones * sizeof (RROutputPtr)); newClones = xalloc (numClones * sizeof (RROutputPtr));
if (!newClones) if (!newClones)
return FALSE; return FALSE;
}
else
newClones = NULL;
if (output->clones) if (output->clones)
xfree (output->clones); xfree (output->clones);
memcpy (newClones, clones, numClones * sizeof (RROutputPtr)); memcpy (newClones, clones, numClones * sizeof (RROutputPtr));
@ -108,9 +113,14 @@ RROutputSetModes (RROutputPtr output,
{ {
RRModePtr *newModes; RRModePtr *newModes;
if (numModes)
{
newModes = xalloc (numModes * sizeof (RRModePtr)); newModes = xalloc (numModes * sizeof (RRModePtr));
if (!newModes) if (!newModes)
return FALSE; return FALSE;
}
else
newModes = NULL;
if (output->modes) if (output->modes)
xfree (output->modes); xfree (output->modes);
memcpy (newModes, modes, numModes * sizeof (RRModePtr)); memcpy (newModes, modes, numModes * sizeof (RRModePtr));
@ -127,9 +137,14 @@ RROutputSetCrtcs (RROutputPtr output,
{ {
RRCrtcPtr *newCrtcs; RRCrtcPtr *newCrtcs;
if (numCrtcs)
{
newCrtcs = xalloc (numCrtcs * sizeof (RRCrtcPtr)); newCrtcs = xalloc (numCrtcs * sizeof (RRCrtcPtr));
if (!newCrtcs) if (!newCrtcs)
return FALSE; return FALSE;
}
else
newCrtcs = NULL;
if (output->crtcs) if (output->crtcs)
xfree (output->crtcs); xfree (output->crtcs);
memcpy (newCrtcs, crtcs, numCrtcs * sizeof (RRCrtcPtr)); memcpy (newCrtcs, crtcs, numCrtcs * sizeof (RRCrtcPtr));
@ -265,9 +280,14 @@ ProcRRGetOutputInfo (ClientPtr client)
((rep.nameLength + 3) >> 2)); ((rep.nameLength + 3) >> 2));
extraLen = rep.length << 2; extraLen = rep.length << 2;
if (extraLen)
{
extra = xalloc (extraLen); extra = xalloc (extraLen);
if (!extra) if (!extra)
return BadAlloc; return BadAlloc;
}
else
extra = NULL;
crtcs = (RRCrtc *) extra; crtcs = (RRCrtc *) extra;
modes = (RRMode *) (crtcs + output->numCrtcs); modes = (RRMode *) (crtcs + output->numCrtcs);

View File

@ -187,9 +187,9 @@ RRScreenSizeSet (ScreenPtr pScreen,
rrScrPriv(pScreen); rrScrPriv(pScreen);
#if RANDR_12_INTERFACE #if RANDR_12_INTERFACE
if (pScrPriv->rrScreenSizeSet) if (pScrPriv->rrScreenSetSize)
{ {
return (*pScrPriv->rrScreenSizeSet) (pScreen, return (*pScrPriv->rrScreenSetSize) (pScreen,
width, height, width, height,
mmWidth, mmHeight); mmWidth, mmHeight);
} }
@ -376,9 +376,14 @@ ProcRRGetScreenResources (ClientPtr client)
((rep.nbytesNames + 3) >> 2)); ((rep.nbytesNames + 3) >> 2));
extraLen = rep.length << 2; extraLen = rep.length << 2;
if (extraLen)
{
extra = xalloc (extraLen); extra = xalloc (extraLen);
if (!extra) if (!extra)
return BadAlloc; return BadAlloc;
}
else
extra = NULL;
crtcs = (RRCrtc *) extra; crtcs = (RRCrtc *) extra;
outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs); outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs);
@ -595,12 +600,18 @@ ProcRRGetScreenInfo (ClientPtr client)
extraLen = (rep.nSizes * sizeof (xScreenSizes) + extraLen = (rep.nSizes * sizeof (xScreenSizes) +
rep.nrateEnts * sizeof (CARD16)); rep.nrateEnts * sizeof (CARD16));
if (extraLen)
{
extra = (CARD8 *) xalloc (extraLen); extra = (CARD8 *) xalloc (extraLen);
if (!extra) if (!extra)
{ {
xfree (pData); xfree (pData);
return BadAlloc; return BadAlloc;
} }
}
else
extra = NULL;
/* /*
* First comes the size information * First comes the size information
*/ */