diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2012-03-02 17:13:27 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2012-03-08 21:18:43 -0800 |
commit | b38ed3d9e9100347c738b3abd12ec4dab1a5f395 (patch) | |
tree | 733b1a776f2388dead68694e7ccacb7c6ac41813 | |
parent | ab99e025529b9029759470e9e085bb344f7fe4f5 (diff) |
Rework si:type:value code to remove need for shadowed namelen variable
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.coopersmith@oracle.com>
-rw-r--r-- | xhost.c | 17 |
1 files changed, 5 insertions, 12 deletions
@@ -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) |