From b38ed3d9e9100347c738b3abd12ec4dab1a5f395 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 2 Mar 2012 17:13:27 -0800 Subject: Rework si:type:value code to remove need for shadowed namelen variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes gcc warning: xhost.c:453:6: warning: declaration of ‘namelen’ shadows a previous local xhost.c:339:9: warning: shadowed declaration is here Also removes unnecessary malloc and memcpy by just using the string pointers we already have, since XAddHost & XRemoveHost will copy the specified length of text from the strings to the Xlib request buffer before returning, not relying on nil termination. Signed-off-by: Alan Coopersmith --- xhost.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/xhost.c b/xhost.c index cf05d59..08f7c79 100644 --- a/xhost.c +++ b/xhost.c @@ -450,7 +450,7 @@ change_host(Display *dpy, char *name, Bool add) if (family == FamilyServerInterpreted) { XServerInterpretedAddress siaddr; - int namelen, rc; + int rc; cp = strchr(name, ':'); if (cp == NULL || cp == name) { @@ -459,23 +459,16 @@ change_host(Display *dpy, char *name, Bool add) ProgramName, name); return 0; } + siaddr.type = name; + siaddr.typelength = cp - name; + siaddr.value = ++cp; + siaddr.valuelength = strlen(cp); ha.family = FamilyServerInterpreted; ha.address = (char *) &siaddr; - namelen = strlen(name); - siaddr.type = malloc(namelen); - if (siaddr.type == NULL) { - return 0; - } - memcpy(siaddr.type, name, namelen); - siaddr.typelength = cp - name; - siaddr.type[siaddr.typelength] = '\0'; - siaddr.value = siaddr.type + siaddr.typelength + 1; - siaddr.valuelength = namelen - (siaddr.typelength + 1); if (add) rc = XAddHost(dpy, &ha); else rc = XRemoveHost(dpy, &ha); - free(siaddr.type); printf( "%s %s%s\n", name, rc == 1 ? "" : "failed when ", add ? add_msg : remove_msg); if (rc != 1) -- cgit v1.2.3