commands: add printf attribute to cmd_results_new()

And fix the resulting build failures.
This commit is contained in:
Simon Ser 2023-02-28 16:24:03 +01:00
parent d6915f6428
commit a7b50f6c9c
19 changed files with 63 additions and 58 deletions

View File

@ -3,6 +3,7 @@
#include <wlr/util/edges.h>
#include "config.h"
#include "stringop.h"
struct sway_container;
@ -76,7 +77,7 @@ struct cmd_results *config_commands_command(char *exec);
/**
* Allocates a cmd_results object.
*/
struct cmd_results *cmd_results_new(enum cmd_status status, const char *error, ...);
struct cmd_results *cmd_results_new(enum cmd_status status, const char *error, ...) _SWAY_ATTRIB_PRINTF(2, 3);
/**
* Frees a cmd_results object.
*/

View File

@ -381,10 +381,13 @@ struct cmd_results *config_command(char *exec, char **new_block) {
sway_log(SWAY_INFO, "Config command: %s", exec);
const struct cmd_handler *handler = find_core_handler(argv[0]);
if (!handler || !handler->handle) {
const char *error = handler
? "Command '%s' is shimmed, but unimplemented"
: "Unknown/invalid command '%s'";
results = cmd_results_new(CMD_INVALID, error, argv[0]);
if (handler) {
results = cmd_results_new(CMD_INVALID,
"Command '%s' is shimmed, but unimplemented", argv[0]);
} else {
results = cmd_results_new(CMD_INVALID,
"Unknown/invalid command '%s'", argv[0]);
}
goto cleanup;
}

View File

@ -17,7 +17,7 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
char *err_str = NULL;
struct criteria *criteria = criteria_parse(argv[0], &err_str);
if (!criteria) {
error = cmd_results_new(CMD_INVALID, err_str);
error = cmd_results_new(CMD_INVALID, "%s", err_str);
free(err_str);
return error;
}

View File

@ -96,7 +96,7 @@ static struct cmd_results *bar_cmd_bind(int argc, char **argv, bool code,
}
if (message) {
free_bar_binding(binding);
error = cmd_results_new(CMD_INVALID, message);
error = cmd_results_new(CMD_INVALID, "%s", message);
free(message);
return error;
} else if (!binding->button) {

View File

@ -26,7 +26,7 @@ static struct cmd_results *tray_bind(int argc, char **argv, bool code) {
}
if (message) {
free(binding);
error = cmd_results_new(CMD_INVALID, message);
error = cmd_results_new(CMD_INVALID, "%s", message);
free(message);
return error;
} else if (!binding->button) {

View File

@ -127,7 +127,7 @@ static struct cmd_results *identify_key(const char* name, bool first_key,
if (!button) {
if (message) {
struct cmd_results *error =
cmd_results_new(CMD_INVALID, message);
cmd_results_new(CMD_INVALID, "%s", message);
free(message);
return error;
} else {
@ -143,7 +143,7 @@ static struct cmd_results *identify_key(const char* name, bool first_key,
if (!button) {
if (message) {
struct cmd_results *error =
cmd_results_new(CMD_INVALID, message);
cmd_results_new(CMD_INVALID, "%s", message);
free(message);
return error;
} else {
@ -182,7 +182,7 @@ static struct cmd_results *identify_key(const char* name, bool first_key,
uint32_t button = get_mouse_bindsym(name, &message);
if (message) {
struct cmd_results *error =
cmd_results_new(CMD_INVALID, message);
cmd_results_new(CMD_INVALID, "%s", message);
free(message);
return error;
} else if (button) {
@ -539,7 +539,7 @@ struct cmd_results *cmd_bind_or_unbind_switch(int argc, char **argv,
free_switch_binding(binding);
return cmd_results_new(CMD_FAILURE,
"Invalid %s command (expected binding with the form "
"<switch>:<state>)", bindtype, argc);
"<switch>:<state>)", bindtype);
}
if (strcmp(split->items[0], "tablet") == 0) {
binding->type = WLR_SWITCH_TYPE_TABLET_MODE;
@ -549,7 +549,8 @@ struct cmd_results *cmd_bind_or_unbind_switch(int argc, char **argv,
free_switch_binding(binding);
return cmd_results_new(CMD_FAILURE,
"Invalid %s command (expected switch binding: "
"unknown switch %s)", bindtype, split->items[0]);
"unknown switch %s)", bindtype,
(const char *)split->items[0]);
}
if (strcmp(split->items[1], "on") == 0) {
binding->trigger = SWAY_SWITCH_TRIGGER_ON;
@ -562,7 +563,7 @@ struct cmd_results *cmd_bind_or_unbind_switch(int argc, char **argv,
return cmd_results_new(CMD_FAILURE,
"Invalid %s command "
"(expected switch state: unknown state %s)",
bindtype, split->items[1]);
bindtype, (const char *)split->items[1]);
}
list_free_items_and_destroy(split);

View File

@ -23,16 +23,16 @@ static struct cmd_results *handle_command(int argc, char **argv, char *cmd_name,
char *err;
int width = (int)strtol(argv[0], &err, 10);
if (*err) {
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}
if (strcmp(argv[1], "x") != 0) {
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}
int height = (int)strtol(argv[2], &err, 10);
if (*err) {
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}
*config_width = width;

View File

@ -14,7 +14,7 @@ struct cmd_results *cmd_for_window(int argc, char **argv) {
char *err_str = NULL;
struct criteria *criteria = criteria_parse(argv[0], &err_str);
if (!criteria) {
error = cmd_results_new(CMD_INVALID, err_str);
error = cmd_results_new(CMD_INVALID, "%s", err_str);
free(err_str);
return error;
}

View File

@ -20,7 +20,7 @@ struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) {
}
if (!argc) {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
if (strcmp(argv[0], "none") == 0) {
@ -38,7 +38,7 @@ struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) {
config->hide_edge_borders = E_NONE;
config->hide_edge_borders_smart = ESMART_NO_GAPS;
} else {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
config->hide_lone_tab = hide_lone_tab;

View File

@ -49,5 +49,5 @@ struct cmd_results *input_cmd_map_to_region(int argc, char **argv) {
error:
free(ic->mapped_to_region);
ic->mapped_to_region = NULL;
return cmd_results_new(CMD_FAILURE, errstr);
return cmd_results_new(CMD_FAILURE, "%s", errstr);
}

View File

@ -21,7 +21,7 @@ struct cmd_results *input_cmd_scroll_button(int argc, char **argv) {
char *message = NULL;
uint32_t button = get_mouse_button(*argv, &message);
if (message) {
error = cmd_results_new(CMD_INVALID, message);
error = cmd_results_new(CMD_INVALID, "%s", message);
free(message);
return error;
} else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN

View File

@ -153,7 +153,7 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
workspace->output);
}
if (new_layout == L_NONE) {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
if (new_layout != old_layout) {
if (container) {

View File

@ -470,7 +470,7 @@ static struct cmd_results *cmd_move_container(bool no_auto_back_and_forth,
if (strcasecmp(argv[1], "number") == 0) {
// move [window|container] [to] "workspace number x"
if (argc < 3) {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
if (!isdigit(argv[2][0])) {
return cmd_results_new(CMD_INVALID,
@ -530,7 +530,7 @@ static struct cmd_results *cmd_move_container(bool no_auto_back_and_forth,
}
destination = &dest_con->node;
} else {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
if (destination->type == N_CONTAINER &&
@ -829,7 +829,7 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
}
if (!argc) {
return cmd_results_new(CMD_INVALID, expected_position_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_position_syntax);
}
bool absolute = false;
@ -839,19 +839,19 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
++argv;
}
if (!argc) {
return cmd_results_new(CMD_INVALID, expected_position_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_position_syntax);
}
if (strcmp(argv[0], "position") == 0) {
--argc;
++argv;
}
if (!argc) {
return cmd_results_new(CMD_INVALID, expected_position_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_position_syntax);
}
if (strcmp(argv[0], "cursor") == 0 || strcmp(argv[0], "mouse") == 0 ||
strcmp(argv[0], "pointer") == 0) {
if (absolute) {
return cmd_results_new(CMD_INVALID, expected_position_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_position_syntax);
}
return cmd_move_to_position_pointer(container);
} else if (strcmp(argv[0], "center") == 0) {
@ -873,7 +873,7 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
}
if (argc < 2) {
return cmd_results_new(CMD_FAILURE, expected_position_syntax);
return cmd_results_new(CMD_FAILURE, "%s", expected_position_syntax);
}
struct movement_amount lx = { .amount = 0, .unit = MOVEMENT_UNIT_INVALID };
@ -886,7 +886,7 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
}
if (argc < 1) {
return cmd_results_new(CMD_FAILURE, expected_position_syntax);
return cmd_results_new(CMD_FAILURE, "%s", expected_position_syntax);
}
struct movement_amount ly = { .amount = 0, .unit = MOVEMENT_UNIT_INVALID };
@ -895,7 +895,7 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
argc -= num_consumed_args;
argv += num_consumed_args;
if (argc > 0) {
return cmd_results_new(CMD_INVALID, expected_position_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_position_syntax);
}
if (ly.unit == MOVEMENT_UNIT_INVALID) {
return cmd_results_new(CMD_INVALID, "Invalid y position specified");
@ -1041,13 +1041,13 @@ struct cmd_results *cmd_move(int argc, char **argv) {
}
if (!argc) {
return cmd_results_new(CMD_INVALID, expected_full_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_full_syntax);
}
// Only `move [window|container] [to] workspace` supports
// `--no-auto-back-and-forth` so treat others as invalid syntax
if (no_auto_back_and_forth && strcasecmp(argv[0], "workspace") != 0) {
return cmd_results_new(CMD_INVALID, expected_full_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_full_syntax);
}
if (strcasecmp(argv[0], "workspace") == 0 ||
@ -1061,5 +1061,5 @@ struct cmd_results *cmd_move(int argc, char **argv) {
strcasecmp(argv[1], "position") == 0)) {
return cmd_move_to_position(argc, argv);
}
return cmd_results_new(CMD_INVALID, expected_full_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_full_syntax);
}

View File

@ -13,7 +13,7 @@ struct cmd_results *cmd_no_focus(int argc, char **argv) {
char *err_str = NULL;
struct criteria *criteria = criteria_parse(argv[0], &err_str);
if (!criteria) {
error = cmd_results_new(CMD_INVALID, err_str);
error = cmd_results_new(CMD_INVALID, "%s", err_str);
free(err_str);
return error;
}

View File

@ -26,7 +26,7 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
"Can't run this command while there's no outputs connected.");
}
if (strcasecmp(argv[0], "workspace") != 0) {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
int argn = 1;
@ -65,7 +65,7 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
++argn; // move past "to"
if (argn >= argc) {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
char *new_name = join_args(argv + argn, argc - argn);

View File

@ -415,7 +415,7 @@ static struct cmd_results *cmd_resize_set(int argc, char **argv) {
argc -= num_consumed_args;
argv += num_consumed_args;
if (width.unit == MOVEMENT_UNIT_INVALID) {
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}
}
@ -427,10 +427,10 @@ static struct cmd_results *cmd_resize_set(int argc, char **argv) {
}
int num_consumed_args = parse_movement_amount(argc, argv, &height);
if (argc > num_consumed_args) {
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}
if (width.unit == MOVEMENT_UNIT_INVALID) {
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}
}
@ -462,7 +462,7 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv,
"[<amount> px|ppt [or <amount> px|ppt]]'";
uint32_t axis = parse_resize_axis(*argv);
if (axis == WLR_EDGE_NONE) {
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}
--argc; ++argv;
@ -473,7 +473,7 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv,
argc -= num_consumed_args;
argv += num_consumed_args;
if (first_amount.unit == MOVEMENT_UNIT_INVALID) {
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}
} else {
first_amount.amount = 10;
@ -483,7 +483,7 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv,
// "or"
if (argc) {
if (strcmp(*argv, "or") != 0) {
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}
--argc; ++argv;
}
@ -493,10 +493,10 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv,
if (argc) {
int num_consumed_args = parse_movement_amount(argc, argv, &second_amount);
if (argc > num_consumed_args) {
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}
if (second_amount.unit == MOVEMENT_UNIT_INVALID) {
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}
} else {
second_amount.amount = 0;
@ -566,5 +566,5 @@ struct cmd_results *cmd_resize(int argc, char **argv) {
const char usage[] = "Expected 'resize <shrink|grow> "
"<width|height|up|down|left|right> [<amount>] [px|ppt]'";
return cmd_results_new(CMD_INVALID, usage);
return cmd_results_new(CMD_INVALID, "%s", usage);
}

View File

@ -18,7 +18,7 @@ static struct cmd_results *handle_command(struct sway_cursor *cursor,
int argc, char **argv) {
if (strcasecmp(argv[0], "move") == 0) {
if (argc < 3) {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
int delta_x = strtol(argv[1], NULL, 10);
int delta_y = strtol(argv[2], NULL, 10);
@ -27,7 +27,7 @@ static struct cmd_results *handle_command(struct sway_cursor *cursor,
wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat);
} else if (strcasecmp(argv[0], "set") == 0) {
if (argc < 3) {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
// map absolute coords (0..1,0..1) to root container coords
float x = strtof(argv[1], NULL) / root->width;
@ -37,7 +37,7 @@ static struct cmd_results *handle_command(struct sway_cursor *cursor,
wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat);
} else {
if (argc < 2) {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
struct cmd_results *error = NULL;
if ((error = press_or_release(cursor, argv[0], argv[1]))) {
@ -92,14 +92,14 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor,
} else if (strcasecmp(action, "release") == 0) {
state = WLR_BUTTON_RELEASED;
} else {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
char *message = NULL;
button = get_mouse_button(button_str, &message);
if (message) {
struct cmd_results *error =
cmd_results_new(CMD_INVALID, message);
cmd_results_new(CMD_INVALID, "%s", message);
free(message);
return error;
} else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN

View File

@ -46,7 +46,7 @@ struct cmd_results *cmd_swap(int argc, char **argv) {
}
if (strcasecmp(argv[0], "container") || strcasecmp(argv[1], "with")) {
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
struct sway_container *current = config->handler_context.container;
@ -65,7 +65,7 @@ struct cmd_results *cmd_swap(int argc, char **argv) {
other = root_find_container(test_mark, value);
} else {
free(value);
return cmd_results_new(CMD_INVALID, expected_syntax);
return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
}
if (!other) {

View File

@ -61,7 +61,7 @@ static struct cmd_results *cmd_workspace_gaps(int argc, char **argv,
const char expected[] = "Expected 'workspace <name> gaps "
"inner|outer|horizontal|vertical|top|right|bottom|left <px>'";
if (gaps_location == 0) {
return cmd_results_new(CMD_INVALID, expected);
return cmd_results_new(CMD_INVALID, "%s", expected);
}
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO,
@ -79,7 +79,7 @@ static struct cmd_results *cmd_workspace_gaps(int argc, char **argv,
char *end;
int amount = strtol(argv[gaps_location + 2], &end, 10);
if (strlen(end)) {
return cmd_results_new(CMD_FAILURE, expected);
return cmd_results_new(CMD_FAILURE, "%s", expected);
}
bool valid = false;
@ -110,7 +110,7 @@ static struct cmd_results *cmd_workspace_gaps(int argc, char **argv,
}
}
if (!valid) {
return cmd_results_new(CMD_INVALID, expected);
return cmd_results_new(CMD_INVALID, "%s", expected);
}
// Prevent invalid gaps configurations.
@ -174,7 +174,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
}
if (root->fullscreen_global) {
return cmd_results_new(CMD_FAILURE, "workspace",
return cmd_results_new(CMD_FAILURE,
"Can't switch workspaces while fullscreen global");
}