(submit/cleanup-vidmode-dispatch) Xext: vidmode: ProcVidModeSetGammaRamp() simplify payload buffer

No need for extra malloc()/free() round just for a tiny buffer that
easily fits on stack. Also allows further simplification of reply
sending by upcoming 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 16:14:33 +02:00
parent 9c76b2795b
commit c83aed6d96

View File

@@ -1537,9 +1537,7 @@ ProcVidModeSetGammaRamp(ClientPtr client)
static int
ProcVidModeGetGammaRamp(ClientPtr client)
{
CARD16 *ramp = NULL;
int length;
size_t ramplen = 0;
ScreenPtr pScreen;
VidModePtr pVidMode;
@@ -1560,14 +1558,15 @@ ProcVidModeGetGammaRamp(ClientPtr client)
length = (stuff->size + 1) & ~1;
if (stuff->size) {
if (!(ramp = xallocarray(length, 3 * sizeof(CARD16))))
return BadAlloc;
ramplen = length * 3 * sizeof(CARD16);
struct {
CARD16 r[length];
CARD16 g[length];
CARD16 b[length];
} ramp;
if (stuff->size) {
if (!pVidMode->GetGammaRamp(pScreen, stuff->size,
ramp, ramp + length, ramp + (length * 2))) {
free(ramp);
ramp.r, ramp.g, ramp.b)) {
return BadValue;
}
}
@@ -1575,20 +1574,19 @@ ProcVidModeGetGammaRamp(ClientPtr client)
xXF86VidModeGetGammaRampReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
.length = (length >> 1) * 3,
.length = bytes_to_int32(sizeof(ramp)),
.size = stuff->size
};
if (client->swapped) {
swaps(&rep.sequenceNumber);
swapl(&rep.length);
swaps(&rep.size);
SwapShorts((short *) ramp, length * 3);
SwapShorts((short *) &ramp, length * 3);
}
WriteToClient(client, sizeof(xXF86VidModeGetGammaRampReply), &rep);
if (stuff->size) {
WriteToClient(client, ramplen, ramp);
free(ramp);
WriteToClient(client, sizeof(ramp), &ramp);
}
return Success;