tools: Fix memset(&p,0,sizeof(p)) idiom in several places.
authorMichael Young <m.a.young@durham.ac.uk>
Wed, 13 Feb 2013 17:00:15 +0000 (17:00 +0000)
committerMichael Young <m.a.young@durham.ac.uk>
Wed, 13 Feb 2013 17:00:15 +0000 (17:00 +0000)
gcc 4.8 identifies several places where code of the form memset(x, 0,
sizeof(x)); is used incorrectly, meaning that less memory is set to
zero than required.

Signed-off-by: Michael Young <m.a.young@durham.ac.uk>
Committed-by: Keir Fraser <keir@xen.org>
tools/blktap2/drivers/md5.c
tools/debugger/kdd/kdd-xen.c
tools/libxc/xc_dom_boot.c
tools/libxl/libxl_qmp.c
tools/python/xen/lowlevel/netlink/libnetlink.c
tools/xenstat/libxenstat/src/xenstat_linux.c

index 27a360eba106b6935246d9aeeaed946e99242722..e765832479aa33adaa433bc196d1da7e78e8664b 100644 (file)
@@ -174,7 +174,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
     MD5Transform(ctx->buf, (uint32_t *) ctx->in);
     byteReverse((unsigned char *) ctx->buf, 4);
     memcpy(digest, ctx->buf, 16);
-    memset(ctx, 0, sizeof(ctx));     /* In case it's sensitive */
+    memset(ctx, 0, sizeof(*ctx));     /* In case it's sensitive */
 }
 
 /* The four core functions - F1 is optimized somewhat */
index b2488c8ecf4d40d4f70a26ef67163d42d0c69060..4fbea7df735169a023bf9368c9e63399d8513f3a 100644 (file)
@@ -333,7 +333,7 @@ int kdd_get_regs(kdd_guest *g, int cpuid, kdd_regs *r, int w64)
     if (!cpu) 
         return -1;
 
-    memset(r, 0, sizeof(r));
+    memset(r, 0, sizeof(*r));
     
     if (w64)
         kdd_get_regs_x86_64(cpu, &r->r64);
index f83aa12d919f55f0e51f993813a7b24d209cfc9d..0cf36d83eb0f460a680905d52eb060272108cde4 100644 (file)
@@ -266,7 +266,7 @@ int xc_dom_boot_image(struct xc_dom_image *dom)
         return rc;
 
     /* let the vm run */
-    memset(ctxt, 0, sizeof(ctxt));
+    memset(ctxt, 0, sizeof(*ctxt));
     if ( (rc = dom->arch_hooks->vcpu(dom, ctxt)) != 0 )
         return rc;
     xc_dom_unmap_all(dom);
index 2ae4c64bbcccb542e0928f5448c7a951ae320d81..644d2c00419f85c7a3337628de9c414b86f840dd 100644 (file)
@@ -378,7 +378,7 @@ static int qmp_open(libxl__qmp_handler *qmp, const char *qmp_socket_path,
     ret = libxl_fd_set_cloexec(qmp->ctx, qmp->qmp_fd, 1);
     if (ret) return -1;
 
-    memset(&qmp->addr, 0, sizeof (&qmp->addr));
+    memset(&qmp->addr, 0, sizeof (qmp->addr));
     qmp->addr.sun_family = AF_UNIX;
     strncpy(qmp->addr.sun_path, qmp_socket_path,
             sizeof (qmp->addr.sun_path));
index 75e4a5160024319b37ae61d5062e66d9673b93b3..c5fc0bf46b18c384b9d4e321e69e1d2d45516fa6 100644 (file)
@@ -37,7 +37,7 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions,
        int sndbuf = 32768;
        int rcvbuf = 32768;
 
-       memset(rth, 0, sizeof(rth));
+       memset(rth, 0, sizeof(*rth));
 
        rth->fd = socket(AF_NETLINK, SOCK_RAW, protocol);
        if (rth->fd < 0) {
index 1543fb21dec3917d5be0538d968d567caf5d1a1e..931b24e1548eae24910c2f84ab7e407897b51ba8 100644 (file)
@@ -113,7 +113,7 @@ int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign
 
        /* Initialize all variables called has passed as non-NULL to zeros */
        if (iface != NULL)
-               memset(iface, 0, sizeof(iface));
+               memset(iface, 0, sizeof(*iface));
        if (rxBytes != NULL)
                *rxBytes = 0;
        if (rxPackets != NULL)