diff options
author | taiyu <taiyu.len@gmail.com> | 2018-09-02 17:07:12 -0700 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2018-09-02 17:07:12 -0700 |
commit | d625d68d4a64ccf277663b26c52f4ca51d494e6a (patch) | |
tree | c7ede86177a4ccdaffc9e8cc52b8d0827674b9fb /common | |
parent | 80270ba086ae3c46ca66f794c5a2111ad1efa1bb (diff) |
prevent ub caused by misaligned stores/loads
Diffstat (limited to 'common')
-rw-r--r-- | common/ipc-client.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c index 24a2f9c2..496fd131 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c @@ -78,8 +78,8 @@ struct ipc_response *ipc_recv_response(int socketfd) { } total = 0; - response->size = data32[0]; - response->type = data32[1]; + memcpy(&response->size, &data32[0], sizeof(data32[0])); + memcpy(&response->type, &data32[1], sizeof(data32[1])); char *payload = malloc(response->size + 1); if (!payload) { goto error_2; @@ -112,8 +112,8 @@ char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint3 char data[ipc_header_size]; uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); memcpy(data, ipc_magic, sizeof(ipc_magic)); - data32[0] = *len; - data32[1] = type; + memcpy(&data32[0], len, sizeof(*len)); + memcpy(&data32[1], &type, sizeof(type)); if (write(socketfd, data, ipc_header_size) == -1) { sway_abort("Unable to send IPC header"); |