1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

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.
This commit is contained in:
Zdenek Kabelac 2010-10-25 11:57:06 +00:00
parent 1b7750c4bd
commit d80f8cf41b
3 changed files with 20 additions and 18 deletions

View File

@ -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.

View 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);

View 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;