From: Zdenek Kabelac Date: Mon, 25 Oct 2010 11:57:06 +0000 (+0000) Subject: Fix clang warning for ntohl(*((uint32_t *)buf)) X-Git-Tag: v2_02_91~1445 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=d80f8cf41bf4d8bae6bf3802018be5e83bc976ff;p=lvm2.git Fix clang warning for ntohl(*((uint32_t *)buf)) 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. --- diff --git a/WHATS_NEW b/WHATS_NEW index 0ca1047c5..3dcdf6cdf 100644 --- 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. diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c index 639f200ad..d17987997 100644 --- a/daemons/dmeventd/dmeventd.c +++ b/daemons/dmeventd/dmeventd.c @@ -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); diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c index abbb968a1..bc8ad993d 100644 --- a/daemons/dmeventd/libdevmapper-event.c +++ b/daemons/dmeventd/libdevmapper-event.c @@ -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;