fix -Wmaybe-unused and -Wstringop-truncation warnings

This commit is contained in:
Michael Stapelberg 2023-01-02 10:45:35 +01:00 committed by Michael Stapelberg
parent d06e87eb8d
commit 8fe28d1a95
6 changed files with 18 additions and 6 deletions

View File

@ -340,8 +340,9 @@ int i3_send_msg(uint32_t type, const char *payload) {
memcpy(walk, &type, sizeof(uint32_t)); memcpy(walk, &type, sizeof(uint32_t));
walk += sizeof(uint32_t); walk += sizeof(uint32_t);
if (payload != NULL) if (payload != NULL) {
strncpy(walk, payload, len); memcpy(walk, payload, len);
}
swrite(i3_connection->fd, buffer, to_write); swrite(i3_connection->fd, buffer, to_write);

View File

@ -39,6 +39,9 @@ static bool tiling_resize_for_border(Con *con, border_t border, xcb_button_press
case BORDER_BOTTOM: case BORDER_BOTTOM:
search_direction = D_DOWN; search_direction = D_DOWN;
break; break;
default:
ELOG("BUG: invalid border value %d\n", border);
return false;
} }
bool res = resize_find_tiling_participants(&first, &second, search_direction, false); bool res = resize_find_tiling_participants(&first, &second, search_direction, false);

View File

@ -1325,7 +1325,7 @@ void cmd_focus_direction(I3_CMD, const char *direction_str) {
HANDLE_EMPTY_MATCH; HANDLE_EMPTY_MATCH;
CMD_FOCUS_WARN_CHILDREN; CMD_FOCUS_WARN_CHILDREN;
direction_t direction; direction_t direction = D_LEFT;
position_t position; position_t position;
bool auto_direction = true; bool auto_direction = true;
if (strcmp(direction_str, "prev") == 0) { if (strcmp(direction_str, "prev") == 0) {

View File

@ -919,7 +919,7 @@ parse_file_result_t parse_file(struct parser_ctx *ctx, const char *f, IncludedFi
continuation = NULL; continuation = NULL;
} }
strncpy(buf + strlen(buf), buffer, strlen(buffer) + 1); strcpy(buf + strlen(buf), buffer);
/* Skip comments and empty lines. */ /* Skip comments and empty lines. */
if (skip_line || comment) { if (skip_line || comment) {
@ -1043,7 +1043,7 @@ parse_file_result_t parse_file(struct parser_ctx *ctx, const char *f, IncludedFi
} else { } else {
/* Copy until the next variable, then copy its value */ /* Copy until the next variable, then copy its value */
strncpy(destwalk, walk, distance); strncpy(destwalk, walk, distance);
strncpy(destwalk + distance, nearest->value, strlen(nearest->value)); strcpy(destwalk + distance, nearest->value);
walk += distance + strlen(nearest->key); walk += distance + strlen(nearest->key);
destwalk += distance + strlen(nearest->value); destwalk += distance + strlen(nearest->value);
} }

View File

@ -340,6 +340,11 @@ int sd_notify(int unset_environment, const char *state) {
goto finish; 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) { if ((fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) {
r = -errno; r = -errno;
goto finish; goto finish;
@ -347,7 +352,7 @@ int sd_notify(int unset_environment, const char *state) {
memset(&sockaddr, 0, sizeof(sockaddr)); memset(&sockaddr, 0, sizeof(sockaddr));
sockaddr.sa.sa_family = AF_UNIX; 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] == '@') if (sockaddr.un.sun_path[0] == '@')
sockaddr.un.sun_path[0] = 0; sockaddr.un.sun_path[0] = 0;

View File

@ -731,6 +731,9 @@ void x_draw_decoration(Con *con) {
/* Make sure the icon does not escape title boundaries */ /* 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); icon_offset_x = min(deco_width - icon_size - icon_padding - title_padding, title_offset_x + predict_text_width(title) + icon_padding);
break; break;
default:
ELOG("BUG: invalid config.title_align value %d\n", config.title_align);
return;
} }
draw_util_text(title, dest_surface, draw_util_text(title, dest_surface,