mirror of
https://github.com/swaywm/sway.git
synced 2025-10-29 05:40:18 -04:00
Remove usage of VLAs.
This commit is contained in:
parent
02bbefda20
commit
aa9d7d8ca1
7 changed files with 32 additions and 11 deletions
|
|
@ -61,7 +61,7 @@ int ipc_open_socket(const char *socket_path) {
|
|||
}
|
||||
|
||||
struct ipc_response *ipc_recv_response(int socketfd) {
|
||||
char data[ipc_header_size];
|
||||
char *data = malloc(sizeof(char) * ipc_header_size);
|
||||
uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic));
|
||||
|
||||
size_t total = 0;
|
||||
|
|
@ -81,6 +81,8 @@ struct ipc_response *ipc_recv_response(int socketfd) {
|
|||
total = 0;
|
||||
memcpy(&response->size, &data32[0], sizeof(data32[0]));
|
||||
memcpy(&response->type, &data32[1], sizeof(data32[1]));
|
||||
free(data);
|
||||
|
||||
char *payload = malloc(response->size + 1);
|
||||
if (!payload) {
|
||||
goto error_2;
|
||||
|
|
@ -99,6 +101,7 @@ struct ipc_response *ipc_recv_response(int socketfd) {
|
|||
return response;
|
||||
error_2:
|
||||
free(response);
|
||||
free(payload);
|
||||
error_1:
|
||||
wlr_log(WLR_ERROR, "Unable to allocate memory for IPC response");
|
||||
return NULL;
|
||||
|
|
@ -110,7 +113,7 @@ void free_ipc_response(struct ipc_response *response) {
|
|||
}
|
||||
|
||||
char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len) {
|
||||
char data[ipc_header_size];
|
||||
char *data = malloc(sizeof(char) * ipc_header_size);
|
||||
uint32_t *data32 = (uint32_t *)(data + sizeof(ipc_magic));
|
||||
memcpy(data, ipc_magic, sizeof(ipc_magic));
|
||||
memcpy(&data32[0], len, sizeof(*len));
|
||||
|
|
@ -120,6 +123,8 @@ char *ipc_single_command(int socketfd, uint32_t type, const char *payload, uint3
|
|||
sway_abort("Unable to send IPC header");
|
||||
}
|
||||
|
||||
free(data);
|
||||
|
||||
if (write(socketfd, payload, *len) == -1) {
|
||||
sway_abort("Unable to send IPC payload");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,11 +87,11 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
|
|||
|
||||
void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
|
||||
int *baseline, double scale, bool markup, const char *fmt, ...) {
|
||||
char buf[max_chars];
|
||||
char *buf = malloc(sizeof(char) * max_chars);
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) {
|
||||
if (vsnprintf(buf, sizeof(char) * max_chars, fmt, args) >= max_chars) {
|
||||
strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow);
|
||||
}
|
||||
va_end(args);
|
||||
|
|
@ -103,15 +103,17 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
|
|||
*baseline = pango_layout_get_baseline(layout) / PANGO_SCALE;
|
||||
}
|
||||
g_object_unref(layout);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void pango_printf(cairo_t *cairo, const char *font,
|
||||
double scale, bool markup, const char *fmt, ...) {
|
||||
char buf[max_chars];
|
||||
char *buf = malloc(sizeof(char) * max_chars);
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) {
|
||||
if (vsnprintf(buf, sizeof(char) * max_chars, fmt, args) >= max_chars) {
|
||||
strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow);
|
||||
}
|
||||
va_end(args);
|
||||
|
|
@ -124,4 +126,6 @@ void pango_printf(cairo_t *cairo, const char *font,
|
|||
pango_cairo_update_layout(cairo, layout);
|
||||
pango_cairo_show_layout(cairo, layout);
|
||||
g_object_unref(layout);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue