From 25af959fe96441123f8ab492427a9390af384918 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 13 Apr 2018 22:35:23 +0900 Subject: [PATCH 1/2] Fix gcc string truncation warnings --- common/ipc-client.c | 2 +- sway/commands.c | 2 +- sway/commands/exec_always.c | 2 +- sway/ipc-server.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/ipc-client.c b/common/ipc-client.c index 117e99108..a88df0800 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c @@ -48,7 +48,7 @@ int ipc_open_socket(const char *socket_path) { sway_abort("Unable to open Unix socket"); } addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path)); + strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1); addr.sun_path[sizeof(addr.sun_path) - 1] = 0; int l = sizeof(struct sockaddr_un); if (connect(socketfd, (struct sockaddr *)&addr, l) == -1) { diff --git a/sway/commands.c b/sway/commands.c index 54d84450e..99f425245 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -601,7 +601,7 @@ struct cmd_results *add_color(const char *name, "Invalid color definition %s", color); } } - strncpy(buffer, color, len); + strcpy(buffer, color); // add default alpha channel if color was defined without it if (len == 7) { buffer[7] = 'f'; diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index 954950e76..af4e4965a 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c @@ -32,7 +32,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { // Put argument into cmd array char cmd[4096]; - strncpy(cmd, tmp, sizeof(cmd)); + strncpy(cmd, tmp, sizeof(cmd) - 1); cmd[sizeof(cmd) - 1] = 0; free(tmp); wlr_log(L_DEBUG, "Executing %s", cmd); diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 045802e10..39d1d0a79 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -64,7 +64,7 @@ void ipc_init(struct sway_server *server) { // We want to use socket name set by user, not existing socket from another sway instance. if (getenv("SWAYSOCK") != NULL && access(getenv("SWAYSOCK"), F_OK) == -1) { - strncpy(ipc_sockaddr->sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr->sun_path)); + strncpy(ipc_sockaddr->sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr->sun_path) - 1); ipc_sockaddr->sun_path[sizeof(ipc_sockaddr->sun_path) - 1] = 0; } From 8490d1662c36bc78d575cd80b68f5a8669e8867f Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 13 Apr 2018 22:35:34 +0900 Subject: [PATCH 2/2] Fix gcc maybe-uninitialized warning --- sway/tree/layout.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sway/tree/layout.c b/sway/tree/layout.c index ae76ca26c..0b6378223 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -288,8 +288,11 @@ void container_move(struct sway_container *container, switch (current->type) { case C_OUTPUT: { - enum wlr_direction wlr_dir; - sway_dir_to_wlr(move_dir, &wlr_dir); + enum wlr_direction wlr_dir = 0; + if (!sway_assert(sway_dir_to_wlr(move_dir, &wlr_dir), + "got invalid direction: %d", move_dir)) { + return; + } double ref_lx = current->x + current->width / 2; double ref_ly = current->y + current->height / 2; struct wlr_output *next = wlr_output_layout_adjacent_output(