summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@guitar.keithp.com>2006-09-20 12:05:52 -0700
committerKeith Packard <keithp@guitar.keithp.com>2006-09-20 12:05:52 -0700
commitd08718d8fd31477e90f13b9e122504c515b46ee0 (patch)
tree2c65df397d32909eebd8ddedc7196cbce3f37852
parentef1f3248cb5fff0a02c0059f865c4d931eba23a6 (diff)
Avoid calling xalloc(0). Change rrScreenSizeSet to rrScreenSetSize.
-rw-r--r--randr/randr.c2
-rw-r--r--randr/randrstr.h6
-rw-r--r--randr/rrcrtc.c56
-rw-r--r--randr/rrmode.c2
-rw-r--r--randr/rroutput.c46
-rw-r--r--randr/rrscreen.c29
6 files changed, 98 insertions, 43 deletions
diff --git a/randr/randr.c b/randr/randr.c
index 5f6ef62e4..5f54dea14 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -198,7 +198,7 @@ Bool RRScreenInit(ScreenPtr pScreen)
pScrPriv->maxHeight = pScrPriv->minHeight = pScreen->height;
#if RANDR_12_INTERFACE
- pScrPriv->rrScreenSizeSet = NULL;
+ pScrPriv->rrScreenSetSize = NULL;
pScrPriv->rrCrtcSet = NULL;
pScrPriv->rrCrtcSetGamma = NULL;
#endif
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 26c180697..80272623c 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -174,7 +174,7 @@ typedef struct _rrScrPriv {
#endif
RRGetInfoProcPtr rrGetInfo;
#if RANDR_12_INTERFACE
- RRScreenSetSizeProcPtr rrScreenSizeSet;
+ RRScreenSetSizeProcPtr rrScreenSetSize;
RRCrtcSetProcPtr rrCrtcSet;
RRCrtcSetGammaProcPtr rrCrtcSetGamma;
#endif
@@ -521,7 +521,7 @@ RRClientKnowsRates (ClientPtr pClient);
RRModePtr
RRModeGet (ScreenPtr pScreen,
xRRModeInfo *modeInfo,
- char *name);
+ const char *name);
/*
* Destroy a mode.
@@ -555,7 +555,7 @@ ProcRRDeleteOutputMode (ClientPtr client);
RROutputPtr
RROutputCreate (ScreenPtr pScreen,
- char *name,
+ const char *name,
int nameLength,
void *devPrivate);
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index c55e08871..90d609ed0 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -94,13 +94,22 @@ RRCrtcNotify (RRCrtcPtr crtc,
{
RROutputPtr *outputs;
- if (crtc->numOutputs)
- outputs = xrealloc (crtc->outputs,
- numOutputs * sizeof (RROutputPtr));
+ if (numOutputs)
+ {
+ if (crtc->numOutputs)
+ outputs = xrealloc (crtc->outputs,
+ numOutputs * sizeof (RROutputPtr));
+ else
+ outputs = xalloc (numOutputs * sizeof (RROutputPtr));
+ if (!outputs)
+ return FALSE;
+ }
else
- outputs = xalloc (numOutputs * sizeof (RROutputPtr));
- if (!outputs)
- return FALSE;
+ {
+ if (crtc->outputs)
+ xfree (crtc->outputs);
+ outputs = NULL;
+ }
crtc->outputs = outputs;
}
for (i = 0; i < numOutputs; i++)
@@ -300,9 +309,14 @@ RRCrtcGammaSetSize (RRCrtcPtr crtc,
if (size == crtc->gammaSize)
return TRUE;
- gamma = xalloc (size * 3 * sizeof (CARD16));
- if (!gamma)
- return FALSE;
+ if (size)
+ {
+ gamma = xalloc (size * 3 * sizeof (CARD16));
+ if (!gamma)
+ return FALSE;
+ }
+ else
+ gamma = NULL;
if (crtc->gammaRed)
xfree (crtc->gammaRed);
crtc->gammaRed = gamma;
@@ -376,9 +390,14 @@ ProcRRGetCrtcInfo (ClientPtr client)
rep.length = rep.nOutput + rep.nPossibleOutput;
extraLen = rep.length << 2;
- extra = xalloc (extraLen);
- if (!extra)
- return BadAlloc;
+ if (extraLen)
+ {
+ extra = xalloc (extraLen);
+ if (!extra)
+ return BadAlloc;
+ }
+ else
+ extra = NULL;
outputs = (RROutput *) extra;
possible = (RROutput *) (outputs + rep.nOutput);
@@ -467,9 +486,14 @@ ProcRRSetCrtcConfig (ClientPtr client)
if (numOutputs == 0)
return BadMatch;
}
- outputs = xalloc (numOutputs * sizeof (RROutputPtr));
- if (!outputs)
- return BadAlloc;
+ if (numOutputs)
+ {
+ outputs = xalloc (numOutputs * sizeof (RROutputPtr));
+ if (!outputs)
+ return BadAlloc;
+ }
+ else
+ outputs = NULL;
outputIds = (RROutput *) (stuff + 1);
for (i = 0; i < numOutputs; i++)
@@ -574,7 +598,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
* for setting screen size. Else, assume the CrtcSet sets
* the size along with the mode
*/
- if (pScrPriv->rrScreenSizeSet)
+ if (pScrPriv->rrScreenSetSize)
{
if (stuff->x + mode->mode.width > pScreen->width)
{
diff --git a/randr/rrmode.c b/randr/rrmode.c
index ab0ea18d9..23ac5305c 100644
--- a/randr/rrmode.c
+++ b/randr/rrmode.c
@@ -27,7 +27,7 @@ RESTYPE RRModeType;
RRModePtr
RRModeGet (ScreenPtr pScreen,
xRRModeInfo *modeInfo,
- char *name)
+ const char *name)
{
rrScrPriv (pScreen);
int i;
diff --git a/randr/rroutput.c b/randr/rroutput.c
index 07dabad2e..3d4c16342 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -30,7 +30,7 @@ RESTYPE RROutputType;
RROutputPtr
RROutputCreate (ScreenPtr pScreen,
- char *name,
+ const char *name,
int nameLength,
void *devPrivate)
{
@@ -89,9 +89,14 @@ RROutputSetClones (RROutputPtr output,
{
RROutputPtr *newClones;
- newClones = xalloc (numClones * sizeof (RROutputPtr));
- if (!newClones)
- return FALSE;
+ if (numClones)
+ {
+ newClones = xalloc (numClones * sizeof (RROutputPtr));
+ if (!newClones)
+ return FALSE;
+ }
+ else
+ newClones = NULL;
if (output->clones)
xfree (output->clones);
memcpy (newClones, clones, numClones * sizeof (RROutputPtr));
@@ -108,9 +113,14 @@ RROutputSetModes (RROutputPtr output,
{
RRModePtr *newModes;
- newModes = xalloc (numModes * sizeof (RRModePtr));
- if (!newModes)
- return FALSE;
+ if (numModes)
+ {
+ newModes = xalloc (numModes * sizeof (RRModePtr));
+ if (!newModes)
+ return FALSE;
+ }
+ else
+ newModes = NULL;
if (output->modes)
xfree (output->modes);
memcpy (newModes, modes, numModes * sizeof (RRModePtr));
@@ -127,9 +137,14 @@ RROutputSetCrtcs (RROutputPtr output,
{
RRCrtcPtr *newCrtcs;
- newCrtcs = xalloc (numCrtcs * sizeof (RRCrtcPtr));
- if (!newCrtcs)
- return FALSE;
+ if (numCrtcs)
+ {
+ newCrtcs = xalloc (numCrtcs * sizeof (RRCrtcPtr));
+ if (!newCrtcs)
+ return FALSE;
+ }
+ else
+ newCrtcs = NULL;
if (output->crtcs)
xfree (output->crtcs);
memcpy (newCrtcs, crtcs, numCrtcs * sizeof (RRCrtcPtr));
@@ -265,9 +280,14 @@ ProcRRGetOutputInfo (ClientPtr client)
((rep.nameLength + 3) >> 2));
extraLen = rep.length << 2;
- extra = xalloc (extraLen);
- if (!extra)
- return BadAlloc;
+ if (extraLen)
+ {
+ extra = xalloc (extraLen);
+ if (!extra)
+ return BadAlloc;
+ }
+ else
+ extra = NULL;
crtcs = (RRCrtc *) extra;
modes = (RRMode *) (crtcs + output->numCrtcs);
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index 58d5152d0..617ae4109 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -187,9 +187,9 @@ RRScreenSizeSet (ScreenPtr pScreen,
rrScrPriv(pScreen);
#if RANDR_12_INTERFACE
- if (pScrPriv->rrScreenSizeSet)
+ if (pScrPriv->rrScreenSetSize)
{
- return (*pScrPriv->rrScreenSizeSet) (pScreen,
+ return (*pScrPriv->rrScreenSetSize) (pScreen,
width, height,
mmWidth, mmHeight);
}
@@ -376,9 +376,14 @@ ProcRRGetScreenResources (ClientPtr client)
((rep.nbytesNames + 3) >> 2));
extraLen = rep.length << 2;
- extra = xalloc (extraLen);
- if (!extra)
- return BadAlloc;
+ if (extraLen)
+ {
+ extra = xalloc (extraLen);
+ if (!extra)
+ return BadAlloc;
+ }
+ else
+ extra = NULL;
crtcs = (RRCrtc *) extra;
outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs);
@@ -595,12 +600,18 @@ ProcRRGetScreenInfo (ClientPtr client)
extraLen = (rep.nSizes * sizeof (xScreenSizes) +
rep.nrateEnts * sizeof (CARD16));
- extra = (CARD8 *) xalloc (extraLen);
- if (!extra)
+ if (extraLen)
{
- xfree (pData);
- return BadAlloc;
+ extra = (CARD8 *) xalloc (extraLen);
+ if (!extra)
+ {
+ xfree (pData);
+ return BadAlloc;
+ }
}
+ else
+ extra = NULL;
+
/*
* First comes the size information
*/