aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c9
-rw-r--r--sway/config.c3
-rw-r--r--sway/stringop.c8
3 files changed, 7 insertions, 13 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 72d53ff0..e7ddfa71 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -383,9 +383,8 @@ static bool cmd_mode(int argc, char **argv) {
// Create mode if it doesnt exist
if (!mode && argc >= 2 && strncmp(argv[1],"{",1) == 0) {
mode = malloc(sizeof*mode);
- mode->name = malloc(strlen(mode_name) + 1);
+ mode->name = strdup(mode_name);
mode->bindings = create_list();
- strcpy(mode->name, mode_name);
list_add(config->modes, mode);
}
if (!mode) {
@@ -834,10 +833,8 @@ static bool cmd_set(int argc, char **argv) {
return false;
}
struct sway_variable *var = malloc(sizeof(struct sway_variable));
- var->name = malloc(strlen(argv[0]) + 1);
- strcpy(var->name, argv[0]);
- var->value = malloc(strlen(argv[1]) + 1);
- strcpy(var->value, argv[1]);
+ var->name = strdup(argv[0]);
+ var->value = strdup(argv[1]);
list_add(config->symbols, var);
return true;
}
diff --git a/sway/config.c b/sway/config.c
index 95cd8b0d..5ece2810 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -249,8 +249,7 @@ bool read_config(FILE *file, bool is_active) {
sway_log(L_ERROR, "Invalid command during config ``%s''", line);
} else if (handler->config_type == CMD_COMPOSITOR_READY && !is_active) {
sway_log(L_DEBUG, "Deferring command ``%s''", line);
- char *cmd = malloc(strlen(line) + 1);
- strcpy(cmd, line);
+ char *cmd = strdup(line);
list_add(config->cmd_queue, cmd);
} else if (!handle_command(line)) {
sway_log(L_DEBUG, "Config load failed for line ``%s''", line);
diff --git a/sway/stringop.c b/sway/stringop.c
index 77faf3f1..1ba54ec6 100644
--- a/sway/stringop.c
+++ b/sway/stringop.c
@@ -17,14 +17,13 @@ char *strip_whitespace(char *_str) {
while (*_str == ' ' || *_str == '\t') {
_str++;
}
- char *str = malloc(strlen(_str) + 1);
- strcpy(str, _str);
+ char *str = strdup(_str);
free(strold);
int i;
for (i = 0; str[i] != '\0'; ++i);
do {
i--;
- } while (i >= 0 && (str[i] == ' ' || str[i] == '\t'));
+ } while (i >= 0 && (str[i] == ' ' || str[i] == '\t'));
str[i + 1] = '\0';
return str;
}
@@ -76,9 +75,8 @@ void strip_quotes(char *str) {
list_t *split_string(const char *str, const char *delims) {
list_t *res = create_list();
- char *copy = malloc(strlen(str) + 1);
+ char *copy = strdup(str);
char *token;
- strcpy(copy, str);
token = strtok(copy, delims);
while(token) {