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 <alan.coopersm...@oracle.com> --- xhost.c | 15 ++++----------- 1 files changed, 4 insertions(+), 11 deletions(-) diff --git a/xhost.c b/xhost.c index cf05d59..736d0ef 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) { @@ -461,21 +461,14 @@ change_host(Display *dpy, char *name, Bool add) } 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.type = name; siaddr.typelength = cp - name; - siaddr.type[siaddr.typelength] = '\0'; - siaddr.value = siaddr.type + siaddr.typelength + 1; - siaddr.valuelength = namelen - (siaddr.typelength + 1); + siaddr.value = ++cp; + siaddr.valuelength = strlen(cp); 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) -- 1.7.3.2 _______________________________________________ xorg-devel@lists.x.org: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel