Xext: xv: more obvious size computations in ProcXvQueryImageAttributes()

Formulate the buffer/field size computations a bit more verbose in
ProcXvQueryImageAttributes(), so they're easier to understand on
reading the code.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-07-10 18:28:42 +02:00
parent dfdb3d3722
commit a15d8d25de

View File

@ -1021,7 +1021,6 @@ ProcXvQueryImageAttributes(ClientPtr client)
XvPortPtr pPort; XvPortPtr pPort;
int32_t *offsets; int32_t *offsets;
int32_t *pitches; int32_t *pitches;
int planeLength;
REQUEST(xvQueryImageAttributesReq); REQUEST(xvQueryImageAttributesReq);
@ -1046,7 +1045,9 @@ ProcXvQueryImageAttributes(ClientPtr client)
num_planes = pImage->num_planes; num_planes = pImage->num_planes;
if (!(offsets = calloc(1, num_planes << 3))) // allocating for `offsets` as well as `pitches` in one block
// both having CARD32 * num_planes (actually int32_t put into CARD32)
if (!(offsets = calloc(num_planes*2, sizeof(CARD32))))
return BadAlloc; return BadAlloc;
pitches = offsets + num_planes; pitches = offsets + num_planes;
@ -1060,7 +1061,7 @@ ProcXvQueryImageAttributes(ClientPtr client)
rep = (xvQueryImageAttributesReply) { rep = (xvQueryImageAttributesReply) {
.type = X_Reply, .type = X_Reply,
.sequenceNumber = client->sequence, .sequenceNumber = client->sequence,
.length = planeLength = num_planes << 1, .length = num_planes * 2, // in 32bit units
.num_planes = num_planes, .num_planes = num_planes,
.width = width, .width = width,
.height = height, .height = height,
@ -1069,8 +1070,8 @@ ProcXvQueryImageAttributes(ClientPtr client)
_WriteQueryImageAttributesReply(client, &rep); _WriteQueryImageAttributesReply(client, &rep);
if (client->swapped) if (client->swapped)
SwapLongs((CARD32 *) offsets, planeLength); SwapLongs((CARD32 *) offsets, rep.length);
WriteToClient(client, planeLength << 2, offsets); WriteToClient(client, rep.length * sizeof(CARD32), offsets);
free(offsets); free(offsets);