Xext: xf86bigfont: split reply header and payload

Split reply header and payload buffers. Making it more coherent with all the
other request handlers, and allows a lot of further simplification by using
generic macros (coming in subsequent commits).

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1600>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-07-12 19:55:56 +02:00 committed by Marge Bot
parent 866f3261c4
commit b5a3ac9527

View File

@ -532,60 +532,59 @@ ProcXF86BigfontQueryFont(ClientPtr client)
{ {
int nfontprops = pFont->info.nprops; int nfontprops = pFont->info.nprops;
int rlength = sizeof(xXF86BigfontQueryFontReply) int rlength = nfontprops * sizeof(xFontProp)
+ nfontprops * sizeof(xFontProp)
+ (nCharInfos > 0 && shmid == -1 + (nCharInfos > 0 && shmid == -1
? nUniqCharInfos * sizeof(xCharInfo) ? nUniqCharInfos * sizeof(xCharInfo)
+ (nCharInfos + 1) / 2 * 2 * sizeof(CARD16) + (nCharInfos + 1) / 2 * 2 * sizeof(CARD16)
: 0); : 0);
xXF86BigfontQueryFontReply *reply = calloc(1, rlength);
char *p;
if (!reply) { xXF86BigfontQueryFontReply rep = {
if (nCharInfos > 0) { .type = X_Reply;
if (shmid == -1) .length = bytes_to_int32(buflength),
free(pIndex2UniqIndex); .sequenceNumber = client->sequence,
if (!pDesc) .minBounds = pFont->info.ink_minbounds,
free(pCI); .maxBounds = pFont->info.ink_maxbounds,
} .minCharOrByte2 = pFont->info.firstCol,
return BadAlloc; .maxCharOrByte2 = pFont->info.lastCol,
} .defaultChar = pFont->info.defaultCh,
reply->type = X_Reply; .nFontProps = pFont->info.nprops,
reply->length = bytes_to_int32(rlength - sizeof(xGenericReply)); .drawDirection = pFont->info.drawDirection,
reply->sequenceNumber = client->sequence; .minByte1 = pFont->info.firstRow,
reply->minBounds = pFont->info.ink_minbounds; .maxByte1 = pFont->info.lastRow,
reply->maxBounds = pFont->info.ink_maxbounds; .allCharsExist = pFont->info.allExist,
reply->minCharOrByte2 = pFont->info.firstCol; .fontAscent = pFont->info.fontAscent,
reply->maxCharOrByte2 = pFont->info.lastCol; .fontDescent = pFont->info.fontDescent,
reply->defaultChar = pFont->info.defaultCh; .nCharInfos = nCharInfos,
reply->nFontProps = pFont->info.nprops; .nUniqCharInfos = nUniqCharInfos,
reply->drawDirection = pFont->info.drawDirection; .shmid = shmid,
reply->minByte1 = pFont->info.firstRow; };
reply->maxByte1 = pFont->info.lastRow;
reply->allCharsExist = pFont->info.allExist;
reply->fontAscent = pFont->info.fontAscent;
reply->fontDescent = pFont->info.fontDescent;
reply->nCharInfos = nCharInfos;
reply->nUniqCharInfos = nUniqCharInfos;
reply->shmid = shmid;
reply->shmsegoffset = 0;
if (client->swapped) { if (client->swapped) {
swaps(&reply->sequenceNumber); swaps(&rep.sequenceNumber);
swapl(&reply->length); swapl(&rep.length);
swapCharInfo(&reply->minBounds); swapCharInfo(&rep.minBounds);
swapCharInfo(&reply->maxBounds); swapCharInfo(&rep.maxBounds);
swaps(&reply->minCharOrByte2); swaps(&rep.minCharOrByte2);
swaps(&reply->maxCharOrByte2); swaps(&rep.maxCharOrByte2);
swaps(&reply->defaultChar); swaps(&rep.defaultChar);
swaps(&reply->nFontProps); swaps(&rep.nFontProps);
swaps(&reply->fontAscent); swaps(&rep.fontAscent);
swaps(&reply->fontDescent); swaps(&rep.fontDescent);
swapl(&reply->nCharInfos); swapl(&rep.nCharInfos);
swapl(&reply->nUniqCharInfos); swapl(&rep.nUniqCharInfos);
swapl(&reply->shmid); swapl(&rep.shmid);
swapl(&reply->shmsegoffset); swapl(&rep.shmsegoffset);
} }
p = (char *) &reply[1];
int rc = Success;
char *buf = calloc(1, rlength);
if (!buf) {
rc = BadAlloc;
goto out;
}
char *p = buf;
{ {
FontPropPtr pFP; FontPropPtr pFP;
xFontProp *prFP; xFontProp *prFP;
@ -621,15 +620,18 @@ ProcXF86BigfontQueryFont(ClientPtr client)
} }
} }
} }
WriteToClient(client, rlength, reply);
free(reply); WriteToClient(client, sizeof(xXF86BigfontQueryFontReply), &rep);
WriteToClient(client, rlength, buf);
free(buf);
out:
if (nCharInfos > 0) { if (nCharInfos > 0) {
if (shmid == -1) if (shmid == -1)
free(pIndex2UniqIndex); free(pIndex2UniqIndex);
if (!pDesc) if (!pDesc)
free(pCI); free(pCI);
} }
return Success; return rc;
} }
} }