mirror of
https://github.com/swaywm/sway.git
synced 2024-12-27 07:26:55 +01:00
Handle calloc failures
This commit is contained in:
parent
a2b9149656
commit
10c8b73075
8 changed files with 39 additions and 2 deletions
|
@ -23,11 +23,14 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
|
|||
char *movecmd = "move container to workspace ";
|
||||
int arglen = strlen(movecmd) + strlen(*argv) + 1;
|
||||
char *cmdlist = calloc(1, arglen);
|
||||
|
||||
if (!cmdlist) {
|
||||
return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate command list");
|
||||
}
|
||||
snprintf(cmdlist, arglen, "%s%s", movecmd, *argv);
|
||||
|
||||
struct criteria *crit = malloc(sizeof(struct criteria));
|
||||
if (!crit) {
|
||||
free(cmdlist);
|
||||
return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate criteria");
|
||||
}
|
||||
crit->crit_raw = strdup(criteria);
|
||||
|
|
|
@ -26,6 +26,9 @@ struct cmd_results *cmd_output(int argc, char **argv) {
|
|||
const char *name = argv[0];
|
||||
|
||||
struct output_config *output = calloc(1, sizeof(struct output_config));
|
||||
if (!output) {
|
||||
return cmd_results_new(CMD_FAILURE, "output", "Unable to allocate output config");
|
||||
}
|
||||
output->x = output->y = output->width = output->height = -1;
|
||||
output->name = strdup(name);
|
||||
output->enabled = -1;
|
||||
|
|
|
@ -61,6 +61,10 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
|
|||
return error;
|
||||
}
|
||||
struct workspace_output *wso = calloc(1, sizeof(struct workspace_output));
|
||||
if (!wso) {
|
||||
return cmd_results_new(CMD_FAILURE, "workspace output",
|
||||
"Unable to allocate workspace output");
|
||||
}
|
||||
wso->workspace = strdup(argv[0]);
|
||||
wso->output = strdup(argv[2]);
|
||||
int i = -1;
|
||||
|
|
|
@ -494,6 +494,9 @@ bool load_main_config(const char *file, bool is_active) {
|
|||
|
||||
struct sway_config *old_config = config;
|
||||
config = calloc(1, sizeof(struct sway_config));
|
||||
if (!config) {
|
||||
sway_abort("Unable to allocate config");
|
||||
}
|
||||
|
||||
config_defaults(config);
|
||||
if (is_active) {
|
||||
|
|
|
@ -23,6 +23,9 @@ static swayc_t *new_swayc(enum swayc_types type) {
|
|||
// next id starts at 1 because 0 is assigned to root_container in layout.c
|
||||
static size_t next_id = 1;
|
||||
swayc_t *c = calloc(1, sizeof(swayc_t));
|
||||
if (!c) {
|
||||
return NULL;
|
||||
}
|
||||
c->id = next_id++;
|
||||
c->handle = -1;
|
||||
c->gaps = -1;
|
||||
|
|
|
@ -23,6 +23,10 @@ static struct panel_config *find_or_create_panel_config(struct wl_resource *reso
|
|||
}
|
||||
sway_log(L_DEBUG, "Creating panel config for resource %p", resource);
|
||||
struct panel_config *config = calloc(1, sizeof(struct panel_config));
|
||||
if (!config) {
|
||||
sway_log(L_ERROR, "Unable to create panel config");
|
||||
return NULL;
|
||||
}
|
||||
list_add(desktop_shell.panels, config);
|
||||
config->wl_resource = resource;
|
||||
return config;
|
||||
|
|
10
sway/input.c
10
sway/input.c
|
@ -11,8 +11,16 @@
|
|||
|
||||
struct input_config *new_input_config(const char* identifier) {
|
||||
struct input_config *input = calloc(1, sizeof(struct input_config));
|
||||
if (!input) {
|
||||
sway_log(L_DEBUG, "Unable to allocate input config");
|
||||
return NULL;
|
||||
}
|
||||
sway_log(L_DEBUG, "new_input_config(%s)", identifier);
|
||||
input->identifier = strdup(identifier);
|
||||
if (!(input->identifier = strdup(identifier))) {
|
||||
free(input);
|
||||
sway_log(L_DEBUG, "Unable to allocate input config");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
input->tap = INT_MIN;
|
||||
input->drag_lock = INT_MIN;
|
||||
|
|
|
@ -245,6 +245,15 @@ json_object *ipc_json_get_version() {
|
|||
|
||||
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
|
||||
char *full_version = calloc(strlen(SWAY_GIT_VERSION) + strlen(SWAY_GIT_BRANCH) + strlen(SWAY_VERSION_DATE) + 20, 1);
|
||||
if (!full_version) {
|
||||
json_object_object_add(version, "human_readable",
|
||||
json_object_new_string("Allocating version string failed"));
|
||||
// TODO: it's stupid that we allocate this in the first place
|
||||
json_object_object_add(version, "major", json_object_new_int(0));
|
||||
json_object_object_add(version, "minor", json_object_new_int(0));
|
||||
json_object_object_add(version, "patch", json_object_new_int(0));
|
||||
return version;
|
||||
}
|
||||
strcat(full_version, SWAY_GIT_VERSION);
|
||||
strcat(full_version, " (");
|
||||
strcat(full_version, SWAY_VERSION_DATE);
|
||||
|
|
Loading…
Reference in a new issue