diff options
author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2016-06-29 13:10:08 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2016-07-05 08:11:41 +0200 |
commit | 5e2e760d3a7b6a671f21169bf5220f482eb2c17d (patch) | |
tree | c63e0e9720b5b31e9c0a8a69410c5ac22d41dd3d /nx-X11/lib | |
parent | 35dbbd7e448f327d0496b76a8170df025b0fcea0 (diff) | |
download | nx-libs-5e2e760d3a7b6a671f21169bf5220f482eb2c17d.tar.gz nx-libs-5e2e760d3a7b6a671f21169bf5220f482eb2c17d.tar.bz2 nx-libs-5e2e760d3a7b6a671f21169bf5220f482eb2c17d.zip |
Avoid 'siAddr' maybe being used uninitialized in XAddHost and XRemoveHost.
Backported from X.org (libX11). Host.c has mainly been copied over from
libX11, contaning 7db7451 as the top commit (which also contains the
greatest change and silences the resp. compiler warning.
commit 7db74514e454d3fc4ff70aa08ddac66bfffda4dd
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Tue Jul 23 22:18:46 2013 -0700
Refactor common code from XAddHost & XRemoveHost into single function
On the Xlib side, the only real difference is the mode flag we send
to the server with the address, so just make that an argument to the
function with the common code for packing the address into the request.
(Aside from labels, gcc 4.7.2 generates identical code before & after
this change due to inlining, verified via diff of gcc -S output.)
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'nx-X11/lib')
-rw-r--r-- | nx-X11/lib/X11/Host.c | 73 |
1 files changed, 26 insertions, 47 deletions
diff --git a/nx-X11/lib/X11/Host.c b/nx-X11/lib/X11/Host.c index 58e9e4a1c..5fcb687cc 100644 --- a/nx-X11/lib/X11/Host.c +++ b/nx-X11/lib/X11/Host.c @@ -44,31 +44,31 @@ X Window System is a trademark of The Open Group. #endif #include "Xlibint.h" -int -XAddHost ( - register Display *dpy, - XHostAddress *host) +static inline int +changehost (Display *dpy, XHostAddress *host, BYTE mode) { - register xChangeHostsReq *req; - register int length; + xChangeHostsReq *req; + int length; XServerInterpretedAddress *siAddr; int addrlen; - - if (host->family == FamilyServerInterpreted) { - siAddr = (XServerInterpretedAddress *) host->address; - addrlen = siAddr->typelength + siAddr->valuelength + 1; - } else { - addrlen = host->length; - } - length = (addrlen + 3) & ~0x3; /* round up */ - + siAddr = host->family == FamilyServerInterpreted ? + (XServerInterpretedAddress *)host->address : NULL; + addrlen = siAddr ? + siAddr->typelength + siAddr->valuelength + 1 : host->length; + + length = (addrlen + 3) & ~0x3; /* round up */ + LockDisplay(dpy); GetReqExtra (ChangeHosts, length, req); - req->mode = HostInsert; + if (!req) { + UnlockDisplay(dpy); + return 0; + } + req->mode = mode; req->hostFamily = host->family; req->hostLength = addrlen; - if (host->family == FamilyServerInterpreted) { + if (siAddr) { char *dest = (char *) NEXTPTR(req,xChangeHostsReq); memcpy(dest, siAddr->type, siAddr->typelength); dest[siAddr->typelength] = '\0'; @@ -82,40 +82,19 @@ XAddHost ( } int -XRemoveHost ( +XAddHost ( register Display *dpy, XHostAddress *host) { - register xChangeHostsReq *req; - register int length; - XServerInterpretedAddress *siAddr; - int addrlen; - - if (host->family == FamilyServerInterpreted) { - siAddr = (XServerInterpretedAddress *) host->address; - addrlen = siAddr->typelength + siAddr->valuelength + 1; - } else { - addrlen = host->length; - } - - length = (addrlen + 3) & ~0x3; /* round up */ + return changehost(dpy, host, HostInsert); +} - LockDisplay(dpy); - GetReqExtra (ChangeHosts, length, req); - req->mode = HostDelete; - req->hostFamily = host->family; - req->hostLength = addrlen; - if (host->family == FamilyServerInterpreted) { - char *dest = (char *) NEXTPTR(req,xChangeHostsReq); - memcpy(dest, siAddr->type, siAddr->typelength); - dest[siAddr->typelength] = '\0'; - memcpy(dest + siAddr->typelength + 1,siAddr->value,siAddr->valuelength); - } else { - memcpy((char *) NEXTPTR(req,xChangeHostsReq), host->address, addrlen); - } - UnlockDisplay(dpy); - SyncHandle(); - return 1; +int +XRemoveHost ( + register Display *dpy, + XHostAddress *host) +{ + return changehost(dpy, host, HostDelete); } int |