Use temporary variables instead of parts of reply structures

When passing variable pointers to functions or otherwise doing long
sequences to compute values for replies, create & use some new
temporary variables, to allow for simpler initialization of reply
structures in the following patches.

Move memsets & other initializations to group with the rest of the
filling in of the reply structure, now that they're not needed so
early in the code path.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
Tested-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
Alan Coopersmith 2012-07-09 19:12:42 -07:00
commit 5b86c072d1
10 changed files with 77 additions and 48 deletions

View file

@ -2801,17 +2801,21 @@ ProcLookupColor(ClientPtr client)
rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP,
client, DixReadAccess);
if (rc == Success) {
xLookupColorReply lcr;
CARD16 exactRed, exactGreen, exactBlue;
if (OsLookupColor
(pcmp->pScreen->myNum, (char *) &stuff[1], stuff->nbytes,
&lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue)) {
&exactRed, &exactGreen, &exactBlue)) {
xLookupColorReply lcr;
lcr.type = X_Reply;
lcr.length = 0;
lcr.sequenceNumber = client->sequence;
lcr.screenRed = lcr.exactRed;
lcr.screenGreen = lcr.exactGreen;
lcr.screenBlue = lcr.exactBlue;
lcr.exactRed = exactRed;
lcr.exactGreen = exactGreen;
lcr.exactBlue = exactBlue;
lcr.screenRed = exactRed;
lcr.screenGreen = exactGreen;
lcr.screenBlue = exactBlue;
(*pcmp->pScreen->ResolveColor) (&lcr.screenRed,
&lcr.screenGreen,
&lcr.screenBlue, pcmp->pVisual);
@ -3109,6 +3113,7 @@ ProcListHosts(ClientPtr client)
{
xListHostsReply reply;
int len, nHosts, result;
BOOL enabled;
pointer pdata;
/* REQUEST(xListHostsReq); */
@ -3120,10 +3125,11 @@ ProcListHosts(ClientPtr client)
if (result != Success)
return result;
result = GetHosts(&pdata, &nHosts, &len, &reply.enabled);
result = GetHosts(&pdata, &nHosts, &len, &enabled);
if (result != Success)
return result;
reply.type = X_Reply;
reply.enabled = enabled;
reply.sequenceNumber = client->sequence;
reply.nHosts = nHosts;
reply.length = bytes_to_int32(len);

View file

@ -4797,6 +4797,7 @@ ProcGrabPointer(ClientPtr client)
GrabMask mask;
WindowPtr confineTo;
CursorPtr oldCursor;
BYTE status;
REQUEST(xGrabPointerReq);
int rc;
@ -4818,7 +4819,6 @@ ProcGrabPointer(ClientPtr client)
return rc;
}
memset(&rep, 0, sizeof(xGrabPointerReply));
oldCursor = NullCursor;
grab = device->deviceGrab.grab;
@ -4833,14 +4833,16 @@ ProcGrabPointer(ClientPtr client)
rc = GrabDevice(client, device, stuff->pointerMode, stuff->keyboardMode,
stuff->grabWindow, stuff->ownerEvents, stuff->time,
&mask, CORE, stuff->cursor, stuff->confineTo, &rep.status);
&mask, CORE, stuff->cursor, stuff->confineTo, &status);
if (rc != Success)
return rc;
if (oldCursor && rep.status == GrabSuccess)
if (oldCursor && status == GrabSuccess)
FreeCursor(oldCursor, (Cursor) 0);
memset(&rep, 0, sizeof(xGrabPointerReply));
rep.type = X_Reply;
rep.status = status;
rep.sequenceNumber = client->sequence;
rep.length = 0;
WriteReplyToClient(client, sizeof(xGrabPointerReply), &rep);
@ -5059,6 +5061,7 @@ int
ProcGrabKeyboard(ClientPtr client)
{
xGrabKeyboardReply rep;
BYTE status;
REQUEST(xGrabKeyboardReq);
int result;
@ -5067,17 +5070,19 @@ ProcGrabKeyboard(ClientPtr client)
REQUEST_SIZE_MATCH(xGrabKeyboardReq);
memset(&rep, 0, sizeof(xGrabKeyboardReply));
mask.core = KeyPressMask | KeyReleaseMask;
result = GrabDevice(client, keyboard, stuff->pointerMode,
stuff->keyboardMode, stuff->grabWindow,
stuff->ownerEvents, stuff->time, &mask, CORE, None,
None, &rep.status);
None, &status);
if (result != Success)
return result;
memset(&rep, 0, sizeof(xGrabKeyboardReply));
rep.type = X_Reply;
rep.status = status;
rep.sequenceNumber = client->sequence;
rep.length = 0;
WriteReplyToClient(client, sizeof(xGrabKeyboardReply), &rep);