aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2023-01-02 10:45:35 +0100
committerMichael Stapelberg <stapelberg@users.noreply.github.com>2023-01-02 11:36:37 +0100
commit8fe28d1a952b342da0069ce6d2b562358f0e1fe7 (patch)
tree4093c087d62fb7be0358ea2fc62e7b0efcc753f1
parentd06e87eb8d9cfa863510d05280fa3a41b8c68205 (diff)
downloadi3-8fe28d1a952b342da0069ce6d2b562358f0e1fe7.tar.gz
i3-8fe28d1a952b342da0069ce6d2b562358f0e1fe7.zip
fix -Wmaybe-unused and -Wstringop-truncation warnings
-rw-r--r--i3bar/src/ipc.c5
-rw-r--r--src/click.c3
-rw-r--r--src/commands.c2
-rw-r--r--src/config_parser.c4
-rw-r--r--src/sd-daemon.c7
-rw-r--r--src/x.c3
6 files changed, 18 insertions, 6 deletions
diff --git a/i3bar/src/ipc.c b/i3bar/src/ipc.c
index 06ddf9b5..3ab4738c 100644
--- a/i3bar/src/ipc.c
+++ b/i3bar/src/ipc.c
@@ -340,8 +340,9 @@ int i3_send_msg(uint32_t type, const char *payload) {
memcpy(walk, &type, sizeof(uint32_t));
walk += sizeof(uint32_t);
- if (payload != NULL)
- strncpy(walk, payload, len);
+ if (payload != NULL) {
+ memcpy(walk, payload, len);
+ }
swrite(i3_connection->fd, buffer, to_write);
diff --git a/src/click.c b/src/click.c
index a5e50632..5381aea5 100644
--- a/src/click.c
+++ b/src/click.c
@@ -39,6 +39,9 @@ static bool tiling_resize_for_border(Con *con, border_t border, xcb_button_press
case BORDER_BOTTOM:
search_direction = D_DOWN;
break;
+ default:
+ ELOG("BUG: invalid border value %d\n", border);
+ return false;
}
bool res = resize_find_tiling_participants(&first, &second, search_direction, false);
diff --git a/src/commands.c b/src/commands.c
index 8a87877c..ae02ab75 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -1325,7 +1325,7 @@ void cmd_focus_direction(I3_CMD, const char *direction_str) {
HANDLE_EMPTY_MATCH;
CMD_FOCUS_WARN_CHILDREN;
- direction_t direction;
+ direction_t direction = D_LEFT;
position_t position;
bool auto_direction = true;
if (strcmp(direction_str, "prev") == 0) {
diff --git a/src/config_parser.c b/src/config_parser.c
index baf5848a..d3eace8b 100644
--- a/src/config_parser.c
+++ b/src/config_parser.c
@@ -919,7 +919,7 @@ parse_file_result_t parse_file(struct parser_ctx *ctx, const char *f, IncludedFi
continuation = NULL;
}
- strncpy(buf + strlen(buf), buffer, strlen(buffer) + 1);
+ strcpy(buf + strlen(buf), buffer);
/* Skip comments and empty lines. */
if (skip_line || comment) {
@@ -1043,7 +1043,7 @@ parse_file_result_t parse_file(struct parser_ctx *ctx, const char *f, IncludedFi
} else {
/* Copy until the next variable, then copy its value */
strncpy(destwalk, walk, distance);
- strncpy(destwalk + distance, nearest->value, strlen(nearest->value));
+ strcpy(destwalk + distance, nearest->value);
walk += distance + strlen(nearest->key);
destwalk += distance + strlen(nearest->value);
}
diff --git a/src/sd-daemon.c b/src/sd-daemon.c
index 84761025..9d698e5f 100644
--- a/src/sd-daemon.c
+++ b/src/sd-daemon.c
@@ -340,6 +340,11 @@ int sd_notify(int unset_environment, const char *state) {
goto finish;
}
+ if (strlen(e) > sizeof(sockaddr.un.sun_path)) {
+ r = -EINVAL;
+ goto finish;
+ }
+
if ((fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) {
r = -errno;
goto finish;
@@ -347,7 +352,7 @@ int sd_notify(int unset_environment, const char *state) {
memset(&sockaddr, 0, sizeof(sockaddr));
sockaddr.sa.sa_family = AF_UNIX;
- strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path));
+ strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path) - 1);
if (sockaddr.un.sun_path[0] == '@')
sockaddr.un.sun_path[0] = 0;
diff --git a/src/x.c b/src/x.c
index 9720e833..48105b03 100644
--- a/src/x.c
+++ b/src/x.c
@@ -731,6 +731,9 @@ void x_draw_decoration(Con *con) {
/* Make sure the icon does not escape title boundaries */
icon_offset_x = min(deco_width - icon_size - icon_padding - title_padding, title_offset_x + predict_text_width(title) + icon_padding);
break;
+ default:
+ ELOG("BUG: invalid config.title_align value %d\n", config.title_align);
+ return;
}
draw_util_text(title, dest_surface,