diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2010-10-25 11:57:06 +0000 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2010-10-25 11:57:06 +0000 |
commit | d80f8cf41bf4d8bae6bf3802018be5e83bc976ff (patch) | |
tree | b5611bfedf74aaac497f84d5d62b4932c463952b /daemons/dmeventd/dmeventd.c | |
parent | 1b7750c4bdaa0d23c4962937eddc3ad18af50f4b (diff) | |
download | lvm2-d80f8cf41bf4d8bae6bf3802018be5e83bc976ff.tar.gz lvm2-d80f8cf41bf4d8bae6bf3802018be5e83bc976ff.tar.xz lvm2-d80f8cf41bf4d8bae6bf3802018be5e83bc976ff.zip |
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.
Diffstat (limited to 'daemons/dmeventd/dmeventd.c')
-rw-r--r-- | daemons/dmeventd/dmeventd.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c index 639f200a..d1798799 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); |