(submit/cleanup-xv-dispatch) Xext: xv: ProcDbeGetVisualInfo() collect payload in buffer before writing

The payload lengths is already known, so we can easily collect the data
in a stack buffer and only need one WriteToClient() operation.

This also clears the road for further simplification/unification of the
reply sending code, coming with follow-up commits.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-07-17 18:50:18 +02:00
parent 014954c3f7
commit 50813e93c6

View File

@ -619,28 +619,29 @@ ProcXvQueryPortAttributes(ClientPtr client)
int size, i; int size, i;
XvPortPtr pPort; XvPortPtr pPort;
XvAttributePtr pAtt; XvAttributePtr pAtt;
xvAttributeInfo Info;
REQUEST(xvQueryPortAttributesReq); REQUEST(xvQueryPortAttributesReq);
REQUEST_SIZE_MATCH(xvQueryPortAttributesReq); REQUEST_SIZE_MATCH(xvQueryPortAttributesReq);
VALIDATE_XV_PORT(stuff->port, pPort, DixGetAttrAccess); VALIDATE_XV_PORT(stuff->port, pPort, DixGetAttrAccess);
int text_size = 0;
for (i = 0, pAtt = pPort->pAdaptor->pAttributes;
i < pPort->pAdaptor->nAttributes; i++, pAtt++) {
text_size += pad_to_int32(strlen(pAtt->name) + 1);
}
int length = (pPort->pAdaptor->nAttributes * sz_xvAttributeInfo)
+ text_size;
xvQueryPortAttributesReply rep = { xvQueryPortAttributesReply rep = {
.type = X_Reply, .type = X_Reply,
.sequenceNumber = client->sequence, .sequenceNumber = client->sequence,
.num_attributes = pPort->pAdaptor->nAttributes, .num_attributes = pPort->pAdaptor->nAttributes,
.length = bytes_to_int32(length),
.text_size = text_size,
}; };
for (i = 0, pAtt = pPort->pAdaptor->pAttributes;
i < pPort->pAdaptor->nAttributes; i++, pAtt++) {
rep.text_size += pad_to_int32(strlen(pAtt->name) + 1);
}
rep.length = (pPort->pAdaptor->nAttributes * sz_xvAttributeInfo)
+ rep.text_size;
rep.length >>= 2;
if (client->swapped) { if (client->swapped) {
swaps(&rep.sequenceNumber); swaps(&rep.sequenceNumber);
swapl(&rep.length); swapl(&rep.length);
@ -650,25 +651,34 @@ ProcXvQueryPortAttributes(ClientPtr client)
WriteToClient(client, sizeof(rep), &rep); WriteToClient(client, sizeof(rep), &rep);
char buf[length];
char * walk = buf;
memset(buf, 0, sizeof(buf));
for (i = 0, pAtt = pPort->pAdaptor->pAttributes; for (i = 0, pAtt = pPort->pAdaptor->pAttributes;
i < pPort->pAdaptor->nAttributes; i++, pAtt++) { i < pPort->pAdaptor->nAttributes; i++, pAtt++) {
size = strlen(pAtt->name) + 1; /* pass the NULL */ size = strlen(pAtt->name) + 1; /* pass the NULL */
Info.flags = pAtt->flags;
Info.min = pAtt->min_value; xvAttributeInfo *Info = (xvAttributeInfo*)walk;
Info.max = pAtt->max_value; Info->flags = pAtt->flags;
Info.size = pad_to_int32(size); Info->min = pAtt->min_value;
Info->max = pAtt->max_value;
Info->size = pad_to_int32(size);
if (client->swapped) { if (client->swapped) {
swapl(&Info.flags); swapl(&Info->flags);
swapl(&Info.size); swapl(&Info->size);
swapl(&Info.min); swapl(&Info->min);
swapl(&Info.max); swapl(&Info->max);
} }
WriteToClient(client, sizeof(Info), &Info); walk += sizeof(xvAttributeInfo);
WriteToClient(client, size, pAtt->name);
memcpy(walk, pAtt->name, size);
walk += pad_to_int32(size);
} }
WriteToClient(client, sizeof(buf), buf);
return Success; return Success;
} }