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,13 +94,22 @@ RRCrtcNotify (RRCrtcPtr crtc,
{ {
RROutputPtr *outputs; RROutputPtr *outputs;
if (crtc->numOutputs) if (numOutputs)
outputs = xrealloc (crtc->outputs, {
numOutputs * sizeof (RROutputPtr)); if (crtc->numOutputs)
outputs = xrealloc (crtc->outputs,
numOutputs * sizeof (RROutputPtr));
else
outputs = xalloc (numOutputs * sizeof (RROutputPtr));
if (!outputs)
return FALSE;
}
else else
outputs = xalloc (numOutputs * sizeof (RROutputPtr)); {
if (!outputs) if (crtc->outputs)
return FALSE; 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;
gamma = xalloc (size * 3 * sizeof (CARD16)); if (size)
if (!gamma) {
return FALSE; gamma = xalloc (size * 3 * sizeof (CARD16));
if (!gamma)
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;
extra = xalloc (extraLen); if (extraLen)
if (!extra) {
return BadAlloc; extra = xalloc (extraLen);
if (!extra)
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;
} }
outputs = xalloc (numOutputs * sizeof (RROutputPtr)); if (numOutputs)
if (!outputs) {
return BadAlloc; outputs = xalloc (numOutputs * sizeof (RROutputPtr));
if (!outputs)
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;
newClones = xalloc (numClones * sizeof (RROutputPtr)); if (numClones)
if (!newClones) {
return FALSE; newClones = xalloc (numClones * sizeof (RROutputPtr));
if (!newClones)
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;
newModes = xalloc (numModes * sizeof (RRModePtr)); if (numModes)
if (!newModes) {
return FALSE; newModes = xalloc (numModes * sizeof (RRModePtr));
if (!newModes)
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;
newCrtcs = xalloc (numCrtcs * sizeof (RRCrtcPtr)); if (numCrtcs)
if (!newCrtcs) {
return FALSE; newCrtcs = xalloc (numCrtcs * sizeof (RRCrtcPtr));
if (!newCrtcs)
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;
extra = xalloc (extraLen); if (extraLen)
if (!extra) {
return BadAlloc; extra = xalloc (extraLen);
if (!extra)
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;
extra = xalloc (extraLen); if (extraLen)
if (!extra) {
return BadAlloc; extra = xalloc (extraLen);
if (!extra)
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));
extra = (CARD8 *) xalloc (extraLen); if (extraLen)
if (!extra)
{ {
xfree (pData); extra = (CARD8 *) xalloc (extraLen);
return BadAlloc; if (!extra)
{
xfree (pData);
return BadAlloc;
}
} }
else
extra = NULL;
/* /*
* First comes the size information * First comes the size information
*/ */