diff options
-rw-r--r-- | common/ipc-client.c | 12 | ||||
-rw-r--r-- | sway/ipc-server.c | 10 |
2 files changed, 9 insertions, 13 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c index ec0454c9..d30212d2 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c | |||
@@ -79,7 +79,6 @@ bool ipc_set_recv_timeout(int socketfd, struct timeval tv) { | |||
79 | 79 | ||
80 | struct ipc_response *ipc_recv_response(int socketfd) { | 80 | struct ipc_response *ipc_recv_response(int socketfd) { |
81 | char data[IPC_HEADER_SIZE]; | 81 | char data[IPC_HEADER_SIZE]; |
82 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); | ||
83 | 82 | ||
84 | size_t total = 0; | 83 | size_t total = 0; |
85 | while (total < IPC_HEADER_SIZE) { | 84 | while (total < IPC_HEADER_SIZE) { |
@@ -95,15 +94,15 @@ struct ipc_response *ipc_recv_response(int socketfd) { | |||
95 | goto error_1; | 94 | goto error_1; |
96 | } | 95 | } |
97 | 96 | ||
98 | total = 0; | 97 | memcpy(&response->size, data + sizeof(ipc_magic), sizeof(uint32_t)); |
99 | memcpy(&response->size, &data32[0], sizeof(data32[0])); | 98 | memcpy(&response->type, data + sizeof(ipc_magic) + sizeof(uint32_t), sizeof(uint32_t)); |
100 | memcpy(&response->type, &data32[1], sizeof(data32[1])); | ||
101 | 99 | ||
102 | char *payload = malloc(response->size + 1); | 100 | char *payload = malloc(response->size + 1); |
103 | if (!payload) { | 101 | if (!payload) { |
104 | goto error_2; | 102 | goto error_2; |
105 | } | 103 | } |
106 | 104 | ||
105 | total = 0; | ||
107 | while (total < response->size) { | 106 | while (total < response->size) { |
108 | ssize_t received = recv(socketfd, payload + total, response->size - total, 0); | 107 | ssize_t received = recv(socketfd, payload + total, response->size - total, 0); |
109 | if (received < 0) { | 108 | if (received < 0) { |
@@ -129,10 +128,9 @@ void free_ipc_response(struct ipc_response *response) { | |||
129 | 128 | ||
130 | char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { | 129 | char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { |
131 | char data[IPC_HEADER_SIZE]; | 130 | char data[IPC_HEADER_SIZE]; |
132 | uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); | ||
133 | memcpy(data, ipc_magic, sizeof(ipc_magic)); | 131 | memcpy(data, ipc_magic, sizeof(ipc_magic)); |
134 | memcpy(&data32[0], len, sizeof(*len)); | 132 | memcpy(data + sizeof(ipc_magic), len, sizeof(*len)); |
135 | memcpy(&data32[1], &type, sizeof(type)); | 133 | memcpy(data + sizeof(ipc_magic) + sizeof(*len), &type, sizeof(type)); |
136 | 134 | ||
137 | if (write(socketfd, data, IPC_HEADER_SIZE) == -1) { | 135 | if (write(socketfd, data, IPC_HEADER_SIZE) == -1) { |
138 | sway_abort("Unable to send IPC header"); | 136 | sway_abort("Unable to send IPC header"); |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 62bdccb8..8ba8b9ba 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -242,7 +242,6 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { | |||
242 | } | 242 | } |
243 | 243 | ||
244 | uint8_t buf[IPC_HEADER_SIZE]; | 244 | uint8_t buf[IPC_HEADER_SIZE]; |
245 | uint32_t *buf32 = (uint32_t*)(buf + sizeof(ipc_magic)); | ||
246 | // Should be fully available, because read_available >= IPC_HEADER_SIZE | 245 | // Should be fully available, because read_available >= IPC_HEADER_SIZE |
247 | ssize_t received = recv(client_fd, buf, IPC_HEADER_SIZE, 0); | 246 | ssize_t received = recv(client_fd, buf, IPC_HEADER_SIZE, 0); |
248 | if (received == -1) { | 247 | if (received == -1) { |
@@ -257,8 +256,8 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { | |||
257 | return 0; | 256 | return 0; |
258 | } | 257 | } |
259 | 258 | ||
260 | memcpy(&client->pending_length, &buf32[0], sizeof(buf32[0])); | 259 | memcpy(&client->pending_length, buf + sizeof(ipc_magic), sizeof(uint32_t)); |
261 | memcpy(&client->pending_type, &buf32[1], sizeof(buf32[1])); | 260 | memcpy(&client->pending_type, buf + sizeof(ipc_magic) + sizeof(uint32_t), sizeof(uint32_t)); |
262 | 261 | ||
263 | if (read_available - received >= (long)client->pending_length) { | 262 | if (read_available - received >= (long)client->pending_length) { |
264 | // Reset pending values. | 263 | // Reset pending values. |
@@ -920,11 +919,10 @@ bool ipc_send_reply(struct ipc_client *client, enum ipc_command_type payload_typ | |||
920 | assert(payload); | 919 | assert(payload); |
921 | 920 | ||
922 | char data[IPC_HEADER_SIZE]; | 921 | char data[IPC_HEADER_SIZE]; |
923 | uint32_t *data32 = (uint32_t*)(data + sizeof(ipc_magic)); | ||
924 | 922 | ||
925 | memcpy(data, ipc_magic, sizeof(ipc_magic)); | 923 | memcpy(data, ipc_magic, sizeof(ipc_magic)); |
926 | memcpy(&data32[0], &payload_length, sizeof(payload_length)); | 924 | memcpy(data + sizeof(ipc_magic), &payload_length, sizeof(payload_length)); |
927 | memcpy(&data32[1], &payload_type, sizeof(payload_type)); | 925 | memcpy(data + sizeof(ipc_magic) + sizeof(payload_length), &payload_type, sizeof(payload_type)); |
928 | 926 | ||
929 | while (client->write_buffer_len + IPC_HEADER_SIZE + payload_length >= | 927 | while (client->write_buffer_len + IPC_HEADER_SIZE + payload_length >= |
930 | client->write_buffer_size) { | 928 | client->write_buffer_size) { |