randr: skip payload assembly in rrGetScreenResources() no data to send
If there's no data to send, the whole reply payload can be skipped entirely. This can also ease the whole code flow, and we don't need to rely on the individual copy loops never trying to dereference a NULL pointer. (what the analyzer can't proof). Also scoping several some variables that are only used when there actually is data to send. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
67b78a9f58
commit
74a3b2b728
|
@ -489,10 +489,6 @@ rrGetScreenResources(ClientPtr client, Bool query)
|
||||||
CARD8 *extra = NULL;
|
CARD8 *extra = NULL;
|
||||||
unsigned long extraLen = 0;
|
unsigned long extraLen = 0;
|
||||||
int i, rc, has_primary = 0;
|
int i, rc, has_primary = 0;
|
||||||
RRCrtc *crtcs;
|
|
||||||
RROutput *outputs;
|
|
||||||
xRRModeInfo *modeinfos;
|
|
||||||
CARD8 *names;
|
|
||||||
|
|
||||||
REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq);
|
REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq);
|
||||||
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
|
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
|
||||||
|
@ -544,20 +540,19 @@ rrGetScreenResources(ClientPtr client, Bool query)
|
||||||
bytes_to_int32(rep.nbytesNames));
|
bytes_to_int32(rep.nbytesNames));
|
||||||
|
|
||||||
extraLen = rep.length << 2;
|
extraLen = rep.length << 2;
|
||||||
if (extraLen) {
|
if (!extraLen)
|
||||||
extra = calloc(1, extraLen);
|
goto finish;
|
||||||
if (!extra) {
|
|
||||||
free(modes);
|
|
||||||
return BadAlloc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
extra = NULL;
|
|
||||||
|
|
||||||
crtcs = (RRCrtc *) extra;
|
extra = calloc(1, extraLen);
|
||||||
outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs);
|
if (!extra) {
|
||||||
modeinfos = (xRRModeInfo *) (outputs + pScrPriv->numOutputs);
|
free(modes);
|
||||||
names = (CARD8 *) (modeinfos + num_modes);
|
return BadAlloc;
|
||||||
|
}
|
||||||
|
|
||||||
|
RRCrtc *crtcs = (RRCrtc *) extra;
|
||||||
|
RROutput *outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs);
|
||||||
|
xRRModeInfo *modeinfos = (xRRModeInfo *) (outputs + pScrPriv->numOutputs);
|
||||||
|
CARD8* names = (CARD8 *) (modeinfos + num_modes);
|
||||||
|
|
||||||
if (pScrPriv->primaryOutput && pScrPriv->primaryOutput->crtc) {
|
if (pScrPriv->primaryOutput && pScrPriv->primaryOutput->crtc) {
|
||||||
has_primary = 1;
|
has_primary = 1;
|
||||||
|
@ -605,8 +600,9 @@ rrGetScreenResources(ClientPtr client, Bool query)
|
||||||
memcpy(names, mode->name, mode->mode.nameLength);
|
memcpy(names, mode->name, mode->mode.nameLength);
|
||||||
names += mode->mode.nameLength;
|
names += mode->mode.nameLength;
|
||||||
}
|
}
|
||||||
free(modes);
|
|
||||||
assert(bytes_to_int32((char *) names - (char *) extra) == rep.length);
|
assert(bytes_to_int32((char *) names - (char *) extra) == rep.length);
|
||||||
|
finish:
|
||||||
|
free(modes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client->swapped) {
|
if (client->swapped) {
|
||||||
|
|
Loading…
Reference in New Issue