]> sourceware.org Git - lvm2.git/commitdiff
Fix clang warning for ntohl(*((uint32_t *)buf))
authorZdenek Kabelac <zkabelac@redhat.com>
Mon, 25 Oct 2010 11:57:06 +0000 (11:57 +0000)
committerZdenek Kabelac <zkabelac@redhat.com>
Mon, 25 Oct 2010 11:57:06 +0000 (11:57 +0000)
We cast (char*) to (uint32_t*) that changes alignment requierements.
For our case the code has been correct as alloca() returns properly
aligned buffer, however this patch make it cleaner and more readable
and avoids warning generation.

WHATS_NEW
daemons/dmeventd/dmeventd.c
daemons/dmeventd/libdevmapper-event.c

index 0ca1047c5e4919e40eb03efeea2406e0e3e612ad..3dcdf6cdf8028d85da6c7cdc31e4431515d1ac2e 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.75 - 
 =====================================
+  Fix warning for changed alignment requirements for dmeventd read/write func.
   Add global/metadata_read_only to use unrepaired metadata in read-only cmds.
   Don't take write lock in vgchange --refresh, --poll or --monitor.
   Skip dm devices in scan if they contain only error targets or are empty.
index 639f200ad59cf93abd18462de13885d65f15fdb9..d179879974253ed0ab2fd06bb66fd6717102d4a7 100644 (file)
@@ -1300,9 +1300,9 @@ static int _client_read(struct dm_event_fifos *fifos,
        unsigned bytes = 0;
        int ret = 0;
        fd_set fds;
-       int header = 1;
        size_t size = 2 * sizeof(uint32_t);     /* status + size */
-       char *buf = alloca(size);
+       uint32_t *header = alloca(size);
+       char *buf = (char *)header;
 
        msg->data = NULL;
 
@@ -1326,9 +1326,9 @@ static int _client_read(struct dm_event_fifos *fifos,
 
                ret = read(fifos->client, buf + bytes, size - bytes);
                bytes += ret > 0 ? ret : 0;
-               if (bytes == 2 * sizeof(uint32_t) && header) {
-                       msg->cmd = ntohl(*((uint32_t *) buf));
-                       msg->size = ntohl(*((uint32_t *) buf + 1));
+               if (header && (bytes == 2 * sizeof(uint32_t))) {
+                       msg->cmd = ntohl(header[0]);
+                       msg->size = ntohl(header[1]);
                        buf = msg->data = dm_malloc(msg->size);
                        size = msg->size;
                        bytes = 0;
@@ -1356,10 +1356,11 @@ static int _client_write(struct dm_event_fifos *fifos,
        fd_set fds;
 
        size_t size = 2 * sizeof(uint32_t) + msg->size;
-       char *buf = alloca(size);
+       uint32_t *header = alloca(size);
+       char *buf = (char *)header;
 
-       *((uint32_t *)buf) = htonl(msg->cmd);
-       *((uint32_t *)buf + 1) = htonl(msg->size);
+       header[0] = htonl(msg->cmd);
+       header[1] = htonl(msg->size);
        if (msg->data)
                memcpy(buf + 2 * sizeof(uint32_t), msg->data, msg->size);
 
index abbb968a178f0b9407c7be2a2b2fdea783df8be3..bc8ad993dd718cef80d17f3cd211ce967a933435 100644 (file)
@@ -230,8 +230,8 @@ static int _daemon_read(struct dm_event_fifos *fifos,
        fd_set fds;
        struct timeval tval = { 0, 0 };
        size_t size = 2 * sizeof(uint32_t);     /* status + size */
-       char *buf = alloca(size);
-       int header = 1;
+       uint32_t *header = alloca(size);
+       char *buf = (char *)header;
 
        while (bytes < size) {
                for (i = 0, ret = 0; (i < 20) && (ret < 1); i++) {
@@ -262,9 +262,9 @@ static int _daemon_read(struct dm_event_fifos *fifos,
                }
 
                bytes += ret;
-               if (bytes == 2 * sizeof(uint32_t) && header) {
-                       msg->cmd = ntohl(*((uint32_t *)buf));
-                       msg->size = ntohl(*((uint32_t *)buf + 1));
+               if (header && (bytes == 2 * sizeof(uint32_t))) {
+                       msg->cmd = ntohl(header[0]);
+                       msg->size = ntohl(header[1]);
                        buf = msg->data = dm_malloc(msg->size);
                        size = msg->size;
                        bytes = 0;
@@ -288,12 +288,13 @@ static int _daemon_write(struct dm_event_fifos *fifos,
        fd_set fds;
 
        size_t size = 2 * sizeof(uint32_t) + msg->size;
-       char *buf = alloca(size);
+       uint32_t *header = alloca(size);
+       char *buf = (char *)header;
        char drainbuf[128];
        struct timeval tval = { 0, 0 };
 
-       *((uint32_t *)buf) = htonl(msg->cmd);
-       *((uint32_t *)buf + 1) = htonl(msg->size);
+       header[0] = htonl(msg->cmd);
+       header[1] = htonl(msg->size);
        memcpy(buf + 2 * sizeof(uint32_t), msg->data, msg->size);
 
        /* drain the answer fifo */
@@ -323,8 +324,7 @@ static int _daemon_write(struct dm_event_fifos *fifos,
                        }
                } while (ret < 1);
 
-               ret = write(fifos->client, ((char *) buf) + bytes,
-                           size - bytes);
+               ret = write(fifos->client, buf + bytes, size - bytes);
                if (ret < 0) {
                        if ((errno == EINTR) || (errno == EAGAIN))
                                continue;
This page took 0.046056 seconds and 5 git commands to generate.