aboutsummaryrefslogtreecommitdiffstats
path: root/common/ipc-client.c
diff options
context:
space:
mode:
authorLibravatar Connor E <38229097+c-edw@users.noreply.github.com>2019-01-16 01:57:53 +0000
committerLibravatar emersion <contact@emersion.fr>2019-01-16 13:02:26 +0100
commitaa9d7d8ca19f4489839f765ad7f190e8141bd001 (patch)
treea00776437e012fb3f800b60c0bb7c25fdbf261b2 /common/ipc-client.c
parentbar_cmd_tray_bind: Use mouse button helpers (diff)
downloadsway-aa9d7d8ca19f4489839f765ad7f190e8141bd001.tar.gz
sway-aa9d7d8ca19f4489839f765ad7f190e8141bd001.tar.zst
sway-aa9d7d8ca19f4489839f765ad7f190e8141bd001.zip
Remove usage of VLAs.
Diffstat (limited to 'common/ipc-client.c')
-rw-r--r--common/ipc-client.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c
index 3515ef0a..13fd8a05 100644
--- a/common/ipc-client.c
+++ b/common/ipc-client.c
@@ -61,7 +61,7 @@ int ipc_open_socket(const char *socket_path) {
61} 61}
62 62
63struct ipc_response *ipc_recv_response(int socketfd) { 63struct ipc_response *ipc_recv_response(int socketfd) {
64 char data[ipc_header_size]; 64 char *data = malloc(sizeof(char) * ipc_header_size);
65 uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); 65 uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic));
66 66
67 size_t total = 0; 67 size_t total = 0;
@@ -81,6 +81,8 @@ struct ipc_response *ipc_recv_response(int socketfd) {
81 total = 0; 81 total = 0;
82 memcpy(&response->size, &data32[0], sizeof(data32[0])); 82 memcpy(&response->size, &data32[0], sizeof(data32[0]));
83 memcpy(&response->type, &data32[1], sizeof(data32[1])); 83 memcpy(&response->type, &data32[1], sizeof(data32[1]));
84 free(data);
85
84 char *payload = malloc(response->size + 1); 86 char *payload = malloc(response->size + 1);
85 if (!payload) { 87 if (!payload) {
86 goto error_2; 88 goto error_2;
@@ -99,6 +101,7 @@ struct ipc_response *ipc_recv_response(int socketfd) {
99 return response; 101 return response;
100error_2: 102error_2:
101 free(response); 103 free(response);
104 free(payload);
102error_1: 105error_1:
103 wlr_log(WLR_ERROR, "Unable to allocate memory for IPC response"); 106 wlr_log(WLR_ERROR, "Unable to allocate memory for IPC response");
104 return NULL; 107 return NULL;
@@ -110,7 +113,7 @@ void free_ipc_response(struct ipc_response *response) {
110} 113}
111 114
112char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) { 115char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) {
113 char data[ipc_header_size]; 116 char *data = malloc(sizeof(char) * ipc_header_size);
114 uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic)); 117 uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic));
115 memcpy(data, ipc_magic, sizeof(ipc_magic)); 118 memcpy(data, ipc_magic, sizeof(ipc_magic));
116 memcpy(&data32[0], len, sizeof(*len)); 119 memcpy(&data32[0], len, sizeof(*len));
@@ -120,6 +123,8 @@ char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint3
120 sway_abort("Unable to send IPC header"); 123 sway_abort("Unable to send IPC header");
121 } 124 }
122 125
126 free(data);
127
123 if (write(socketfd, payload, *len) == -1) { 128 if (write(socketfd, payload, *len) == -1) {
124 sway_abort("Unable to send IPC payload"); 129 sway_abort("Unable to send IPC payload");
125 } 130 }