From 712febb9b4bd93223b963343d5c54c04fcb0c458 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 3 Apr 2025 18:57:14 +0200 Subject: [PATCH] dix: write out X_ListFonts reply directly No need for using a complex callback machinery, if we just move the little pieces of byte-swapping directly into the request handler. Signed-off-by: Enrico Weigelt, metux IT consult --- dix/dixfonts.c | 26 +++++++++++++++----------- dix/swaprep.c | 11 +---------- dix/tables.c | 2 +- include/swaprep.h | 4 ---- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/dix/dixfonts.c b/dix/dixfonts.c index c2275d0bb..26ccdb1c9 100644 --- a/dix/dixfonts.c +++ b/dix/dixfonts.c @@ -564,9 +564,6 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) int nnames; int stringLens; int i; - xListFontsReply reply; - char *bufptr; - char *bufferStart; int aliascount = 0; if (client->clientGone) { @@ -748,16 +745,17 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) for (i = 0; i < nnames; i++) stringLens += (names->length[i] <= 255) ? names->length[i] : 0; - reply = (xListFontsReply) { + xListFontsReply rep = { .type = X_Reply, .length = bytes_to_int32(stringLens + nnames), .nFonts = nnames, .sequenceNumber = client->sequence }; - bufptr = bufferStart = calloc(1, reply.length << 2); + char *bufferStart = calloc(1, rep.length << 2); + char *bufptr = bufferStart; - if (!bufptr && reply.length) { + if (!bufptr && rep.length) { SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); goto bail; } @@ -767,17 +765,23 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) */ for (i = 0; i < nnames; i++) { if (names->length[i] > 255) - reply.nFonts--; + rep.nFonts--; else { *bufptr++ = names->length[i]; memcpy(bufptr, names->names[i], names->length[i]); bufptr += names->length[i]; } } - nnames = reply.nFonts; - reply.length = bytes_to_int32(stringLens + nnames); - client->pSwapReplyFunc = ReplySwapVector[X_ListFonts]; - WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply); + nnames = rep.nFonts; + rep.length = bytes_to_int32(stringLens + nnames); + + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swaps(&rep.nFonts); + } + + WriteToClient(client, sizeof(rep), &rep); WriteToClient(client, stringLens + nnames, bufferStart); free(bufferStart); diff --git a/dix/swaprep.c b/dix/swaprep.c index de885f9a7..109241068 100644 --- a/dix/swaprep.c +++ b/dix/swaprep.c @@ -258,7 +258,7 @@ SwapCharInfo(xCharInfo * pInfo) swaps(&pInfo->attributes); } -static void _X_COLD +void SwapFontInfo(xQueryFontReply * pr) { swaps(&pr->minCharOrByte2); @@ -316,15 +316,6 @@ SQueryTextExtentsReply(ClientPtr pClient, int size, WriteToClient(pClient, size, pRep); } -void _X_COLD -SListFontsReply(ClientPtr pClient, int size, xListFontsReply * pRep) -{ - swaps(&pRep->sequenceNumber); - swapl(&pRep->length); - swaps(&pRep->nFonts); - WriteToClient(pClient, size, pRep); -} - void _X_COLD SListFontsWithInfoReply(ClientPtr pClient, int size, xListFontsWithInfoReply * pRep) diff --git a/dix/tables.c b/dix/tables.c index b14ccba66..cfad1dec6 100644 --- a/dix/tables.c +++ b/dix/tables.c @@ -764,7 +764,7 @@ ReplySwapPtr ReplySwapVector[256] = { ReplyNotSwappd, ReplyNotSwappd, (ReplySwapPtr) SQueryTextExtentsReply, - (ReplySwapPtr) SListFontsReply, + ReplyNotSwappd, (ReplySwapPtr) SListFontsWithInfoReply, /* 50 */ ReplyNotSwappd, (ReplySwapPtr) SGetFontPathReply, diff --git a/include/swaprep.h b/include/swaprep.h index 44750eeea..c673f13af 100644 --- a/include/swaprep.h +++ b/include/swaprep.h @@ -69,10 +69,6 @@ extern void SQueryTextExtentsReply(ClientPtr /* pClient */ , xQueryTextExtentsReply * /* pRep */ ); -extern void SListFontsReply(ClientPtr /* pClient */ , - int /* size */ , - xListFontsReply * /* pRep */ ); - extern void SListFontsWithInfoReply(ClientPtr /* pClient */ , int /* size */ , xListFontsWithInfoReply *