WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] tools: warn_unused_result build fixes.

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] tools: warn_unused_result build fixes.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 14 Jun 2007 12:55:43 -0700
Delivery-date: Thu, 14 Jun 2007 15:24:50 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1181644711 -3600
# Node ID b515e66234e83b6b2dd2d5795945b2575fb188c9
# Parent  634b7f7f8584f478c9e45a98998c7e7c1b8e3b3d
tools: warn_unused_result build fixes.

Note that some of the existing error checking for asprintf was wrong
for Linux.  asprintf in glibc returns -1 on error, but leaves the
pointer uninitialized.  Only the BSDs zero out the pointer on error.

Also, while fixing these warnings I saw several error paths that were
incorrect.  This patch minimally fixes the warn_unused_result; more
complete error path cleanup will be a later patch.

Signed-off-by:  Charles Coffing <ccoffing@xxxxxxxxxx>
---
 tools/blktap/drivers/blktapctrl.c |   27 +++++++++++++++-------
 tools/blktap/drivers/block-qcow.c |    7 ++++-
 tools/blktap/drivers/tapdisk.c    |    3 +-
 tools/blktap/lib/xenbus.c         |    6 +----
 tools/blktap/lib/xs_api.c         |   45 ++++++++++++++++++--------------------
 tools/console/daemon/io.c         |    5 +++-
 6 files changed, 53 insertions(+), 40 deletions(-)

diff -r 634b7f7f8584 -r b515e66234e8 tools/blktap/drivers/blktapctrl.c
--- a/tools/blktap/drivers/blktapctrl.c Tue Jun 12 11:32:03 2007 +0100
+++ b/tools/blktap/drivers/blktapctrl.c Tue Jun 12 11:38:31 2007 +0100
@@ -143,7 +143,8 @@ static int get_new_dev(int *major, int *
                return -1;
        }
 
-       asprintf(&devname,"%s/%s%d",BLKTAP_DEV_DIR, BLKTAP_DEV_NAME, *minor);
+       if (asprintf(&devname,"%s/%s%d",BLKTAP_DEV_DIR, BLKTAP_DEV_NAME, 
*minor) == -1)
+               return -1;
        make_blktap_dev(devname,*major,*minor); 
        DPRINTF("Received device id %d and major %d, "
                "sent domid %d and be_id %d\n",
@@ -495,20 +496,27 @@ int blktapctrl_new_blkif(blkif_t *blkif)
 
                if (!exist) {
                        DPRINTF("Process does not exist:\n");
-                       asprintf(&rdctldev, 
-                                "%s/tapctrlread%d", BLKTAP_CTRL_DIR, minor);
+                       if (asprintf(&rdctldev,
+                                    "%s/tapctrlread%d", BLKTAP_CTRL_DIR, 
minor) == -1)
+                               return -1;
+                       if (asprintf(&wrctldev,
+                                    "%s/tapctrlwrite%d", BLKTAP_CTRL_DIR, 
minor) == -1) {
+                               free(rdctldev);
+                               return -1;
+                       }
+                       if (asprintf(&cmd, "tapdisk %s %s", wrctldev, rdctldev) 
== -1) {
+                               free(rdctldev);
+                               free(wrctldev);
+                               return -1;
+                       }
+
                        blkif->fds[READ] = open_ctrl_socket(rdctldev);
-
-
-                       asprintf(&wrctldev, 
-                                "%s/tapctrlwrite%d", BLKTAP_CTRL_DIR, minor);
                        blkif->fds[WRITE] = open_ctrl_socket(wrctldev);
                        
                        if (blkif->fds[READ] == -1 || blkif->fds[WRITE] == -1) 
                                goto fail;
 
                        /*launch the new process*/
-                       asprintf(&cmd, "tapdisk %s %s", wrctldev, rdctldev);
                        DPRINTF("Launching process, CMDLINE [%s]\n",cmd);
                        if (system(cmd) == -1) {
                                DPRINTF("Unable to fork, cmdline: [%s]\n",cmd);
@@ -692,7 +700,8 @@ int main(int argc, char *argv[])
        register_new_unmap_hook(unmap_blktapctrl);
 
        /* Attach to blktap0 */
-       asprintf(&devname,"%s/%s0", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME);
+       if (asprintf(&devname,"%s/%s0", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME) == -1)
+                goto open_failed;
        if ((ret = xc_find_device_number("blktap0")) < 0) {
                DPRINTF("couldn't find device number for 'blktap0'\n");
                goto open_failed;
diff -r 634b7f7f8584 -r b515e66234e8 tools/blktap/drivers/block-qcow.c
--- a/tools/blktap/drivers/block-qcow.c Tue Jun 12 11:32:03 2007 +0100
+++ b/tools/blktap/drivers/block-qcow.c Tue Jun 12 11:38:31 2007 +0100
@@ -871,7 +871,10 @@ int tdqcow_open (struct disk_driver *dd,
        }
 
        s->fd = fd;
-       asprintf(&s->name,"%s", name);
+       if (asprintf(&s->name,"%s", name) == -1) {
+               close(fd);
+               return -1;
+       }
 
        ASSERT(sizeof(QCowHeader) + sizeof(QCowHeader_ext) < 512);
 
@@ -1165,7 +1168,7 @@ int tdqcow_close(struct disk_driver *dd)
                offset = sizeof(QCowHeader) + sizeof(uint32_t);
                lseek(fd, offset, SEEK_SET);
                out = cpu_to_be32(cksum);
-               write(fd, &out, sizeof(uint32_t));
+               if (write(fd, &out, sizeof(uint32_t))) ;
                close(fd);
        }
 
diff -r 634b7f7f8584 -r b515e66234e8 tools/blktap/drivers/tapdisk.c
--- a/tools/blktap/drivers/tapdisk.c    Tue Jun 12 11:32:03 2007 +0100
+++ b/tools/blktap/drivers/tapdisk.c    Tue Jun 12 11:38:31 2007 +0100
@@ -220,7 +220,8 @@ static int map_new_dev(struct td_state *
        fd_list_entry_t *ptr;
        int page_size;
 
-       asprintf(&devname,"%s/%s%d", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME, minor);
+       if (asprintf(&devname,"%s/%s%d", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME, 
minor) == -1)
+               return -1;
        tap_fd = open(devname, O_RDWR);
        if (tap_fd == -1) 
        {
diff -r 634b7f7f8584 -r b515e66234e8 tools/blktap/lib/xenbus.c
--- a/tools/blktap/lib/xenbus.c Tue Jun 12 11:32:03 2007 +0100
+++ b/tools/blktap/lib/xenbus.c Tue Jun 12 11:38:31 2007 +0100
@@ -360,8 +360,7 @@ int add_blockdevice_probe_watch(struct x
        char *path;
        struct xenbus_watch *vbd_watch;
        
-       asprintf(&path, "/local/domain/%s/backend/tap", domid);
-       if (path == NULL) 
+       if (asprintf(&path, "/local/domain/%s/backend/tap", domid) == -1)
                return -ENOMEM;
        
        vbd_watch = (struct xenbus_watch *)malloc(sizeof(struct xenbus_watch));
@@ -399,8 +398,7 @@ int watch_for_domid(struct xs_handle *h)
        struct xenbus_watch *domid_watch;
        char *path = NULL;
 
-       asprintf(&path, "/local/domain");
-       if (path == NULL) 
+       if (asprintf(&path, "/local/domain") == -1)
                return -ENOMEM;
 
        domid_watch = malloc(sizeof(struct xenbus_watch));
diff -r 634b7f7f8584 -r b515e66234e8 tools/blktap/lib/xs_api.c
--- a/tools/blktap/lib/xs_api.c Tue Jun 12 11:32:03 2007 +0100
+++ b/tools/blktap/lib/xs_api.c Tue Jun 12 11:38:31 2007 +0100
@@ -126,10 +126,12 @@ int xs_printf(struct xs_handle *h, const
        ret = vasprintf(&buf, fmt, ap);
        va_end(ap);
        
-       asprintf(&path, "%s/%s", dir, node);
-       
-       if ((path == NULL) || (buf == NULL))
-               return 0;
+       if (ret == -1)
+               return ENOMEM;
+       if (asprintf(&path, "%s/%s", dir, node) == -1) {
+               free(buf);
+               return ENOMEM;
+       }
 
        ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1);
        
@@ -180,10 +182,11 @@ char *get_dom_domid(struct xs_handle *h)
        
        e = xs_directory(h, xth, "/local/domain", &num);
        if (e == NULL)
-               return NULL;
+               goto done;
 
        for (i = 0; (i < num) && (domid == NULL); i++) {
-               asprintf(&path, "/local/domain/%s/name", e[i]);
+               if (asprintf(&path, "/local/domain/%s/name", e[i]) == -1)
+                       break;
                val = xs_read(h, xth, path, &len);
                free(path);
                if (val == NULL)
@@ -191,29 +194,31 @@ char *get_dom_domid(struct xs_handle *h)
                
                if (strcmp(val, DOMNAME) == 0) {
                        /* match! */
-                       asprintf(&path, "/local/domain/%s/domid", e[i]);
+                       if (asprintf(&path, "/local/domain/%s/domid", e[i]) == 
-1) {
+                               free(val);
+                               break;
+                       }
                        domid = xs_read(h, xth, path, &len);
                        free(path);
                }
                free(val);
        }
+done:
        xs_transaction_end(h, xth, 0);
-       
-       free(e);
+       if (e)
+               free(e);
        return domid;
 }
 
 int convert_dev_name_to_num(char *name) {
-       char *p_sd, *p_hd, *p_xvd, *p_plx, *p, *alpha,*ptr;
+       char *p, *ptr;
        int majors[10] = {3,22,33,34,56,57,88,89,90,91};
        int maj,i,ret = 0;
-
-       asprintf(&p_sd,"/dev/sd");
-       asprintf(&p_hd,"/dev/hd");
-       asprintf(&p_xvd,"/dev/xvd");
-       asprintf(&p_plx,"plx");
-       asprintf(&alpha,"abcdefghijklmnop");
-       
+       char *p_sd = "/dev/sd";
+       char *p_hd = "/dev/hd";
+       char *p_xvd = "/dev/xvd";
+       char *p_plx = "plx";
+       char *alpha = "abcdefghijklmnop";
 
        if (strstr(name, p_sd) != NULL) {
                p = name + strlen(p_sd);
@@ -251,12 +256,6 @@ int convert_dev_name_to_num(char *name) 
                ret = BASE_DEV_VAL;
        }
 
-       free(p_sd);
-       free(p_hd);
-       free(p_xvd);
-       free(p_plx);
-       free(alpha);
-
        return ret;
 }
 
diff -r 634b7f7f8584 -r b515e66234e8 tools/console/daemon/io.c
--- a/tools/console/daemon/io.c Tue Jun 12 11:32:03 2007 +0100
+++ b/tools/console/daemon/io.c Tue Jun 12 11:38:31 2007 +0100
@@ -303,7 +303,10 @@ int xs_gather(struct xs_handle *xs, cons
                void *result = va_arg(ap, void *);
                char *p;
 
-               asprintf(&path, "%s/%s", dir, name);
+               if (asprintf(&path, "%s/%s", dir, name) == -1) {
+                       ret = ENOMEM;
+                       break;
+               }
                p = xs_read(xs, XBT_NULL, path, NULL);
                free(path);
                if (p == NULL) {

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] tools: warn_unused_result build fixes., Xen patchbot-unstable <=