hirc

IRC client
Log | Files | Refs

commit 745342f3cc055001765a625cea8065edc4b57fa7
parent 6d5e4178ba009ddf79b6f4b68c64737e2a9faa12
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 22 Jan 2022 20:12:33 +0000

s/commands.c s/config.c s/handle.c s/nick.c s/ui.c: use e(malloc|strdup)

Diffstat:
Msrc/commands.c | 10+++++-----
Msrc/config.c | 2+-
Msrc/handle.c | 8++++----
Msrc/nick.c | 6+++---
Msrc/ui.c | 38+++++++++++++++++++-------------------
5 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -1431,17 +1431,17 @@ alias_add(char *alias, char *cmd) { if (!alias || !cmd) return -1; - p = malloc(sizeof(struct Alias)); + p = emalloc(sizeof(struct Alias)); if (*alias != '/') { - tmp = malloc(strlen(alias) + 2); + tmp = emalloc(strlen(alias) + 2); snprintf(tmp, strlen(alias) + 2, "/%s", alias); p->alias = tmp; - } else p->alias = strdup(alias); + } else p->alias = estrdup(alias); if (*cmd != '/') { - tmp = malloc(strlen(cmd) + 2); + tmp = emalloc(strlen(cmd) + 2); snprintf(tmp, strlen(cmd) + 2, "/%s", cmd); p->cmd = tmp; - } else p->cmd = strdup(cmd); + } else p->cmd = estrdup(cmd); p->prev = NULL; p->next = aliases; if (aliases) diff --git a/src/config.c b/src/config.c @@ -1310,7 +1310,7 @@ config_setr(char *name, long a, long b) { void config_set(char *name, char *val) { - char *str = val ? strdup(val) : NULL; + char *str = val ? estrdup(val) : NULL; char *tok[3], *save, *p; tok[0] = strtok_r(val, " ", &save); diff --git a/src/handle.c b/src/handle.c @@ -325,7 +325,7 @@ handle_RPL_CHANNELMODEIS(struct Server *server, struct History *msg) { chan = chan_add(server, &server->channels, *(msg->params+2), 0); free(chan->mode); - chan->mode = strdup(*(msg->params+3)); + chan->mode = estrdup(*(msg->params+3)); if (handle_expect_get(server, Expect_channelmodeis)) { hist_addp(chan->history, msg, Activity_status, HIST_DFL); @@ -464,7 +464,7 @@ handle_TOPIC(struct Server *server, struct History *msg) { if ((chan = chan_get(&server->channels, *(msg->params+1), -1)) != NULL) { hist_addp(chan->history, msg, Activity_status, HIST_DFL); free(chan->topic); - chan->topic = *(msg->params+2) ? strdup(*(msg->params+2)) : NULL; + chan->topic = *(msg->params+2) ? estrdup(*(msg->params+2)) : NULL; } } @@ -504,7 +504,7 @@ handle_RPL_TOPIC(struct Server *server, struct History *msg) { return; free(chan->topic); - chan->topic = topic ? strdup(topic) : NULL; + chan->topic = topic ? estrdup(topic) : NULL; if (strcmp_n(target, handle_expect_get(server, Expect_topic)) == 0) { hist_addp(chan->history, msg, Activity_status, HIST_DFL); @@ -557,7 +557,7 @@ handle_expect(struct Server *server, enum Expect cmd, char *about) { return; free(server->expect[cmd]); - server->expect[cmd] = about ? strdup(about) : NULL; + server->expect[cmd] = about ? estrdup(about) : NULL; } char * diff --git a/src/nick.c b/src/nick.c @@ -91,9 +91,9 @@ prefix_tokenize(char *prefix, char **nick, char **ident, char **host) { } } - if (nick && *nick) *nick = strdup(*nick); - if (ident && *ident) *ident = strdup(*ident); - if (host && *host) *host = strdup(*host); + if (nick && *nick) *nick = estrdup(*nick); + if (ident && *ident) *ident = estrdup(*ident); + if (host && *host) *host = estrdup(*host); } void diff --git a/src/ui.c b/src/ui.c @@ -427,7 +427,7 @@ ui_read(void) { case KEY_UP: if (histindex < INPUT_HIST_MAX && input.history[histindex + 1]) { if (histindex == -1) - backup = strdup(input.string); + backup = estrdup(input.string); histindex++; strlcpy(input.string, input.history[histindex], sizeof(input.string)); input.counter = strlen(input.string); @@ -461,7 +461,7 @@ ui_read(void) { /* free checks for null */ free(input.history[INPUT_HIST_MAX - 1]); memmove(input.history + 1, input.history, (sizeof(input.history) / INPUT_HIST_MAX) * (INPUT_HIST_MAX - 1)); - input.history[0] = strdup(input.string); + input.history[0] = estrdup(input.string); input.string[0] = '\0'; input.counter = 0; break; @@ -1309,7 +1309,7 @@ ui_format(struct Window *window, char *format, struct History *hist) { if (!recursive && hist && config_getl("timestamp.toggle")) { recursive = 1; - ts = strdup(ui_format(NULL, config_gets("format.ui.timestamp"), hist)); + ts = estrdup(ui_format(NULL, config_gets("format.ui.timestamp"), hist)); recursive = 0; } else { ts = ""; @@ -1458,7 +1458,7 @@ ui_format(struct Window *window, char *format, struct History *hist) { * the length of hidden characters. Add this onto the * margin to pad out properly. */ /* Save ret for use in snprintf */ - save = strdup(ret); + save = estrdup(ret); rc = snprintf(ret, sizeof(ret), "%1$*3$s%2$s", save, config_gets("divider.string"), config_getl("divider.margin") + (strlen(ret) - ui_strlenc(window, ret, NULL))); free(save); @@ -1475,10 +1475,10 @@ ui_format(struct Window *window, char *format, struct History *hist) { /* pad: and nick: must come last as it modifies content */ if (strncmp(content, "pad:", strlen("pad:")) == 0 && strchr(content, ',')) { pn = strtol(content + strlen("pad:"), NULL, 10); - content = strdup(ui_format_get_content(strchr(format+2+strlen("pad:"), ',') + 1, 1)); - save = strdup(ret); + content = estrdup(ui_format_get_content(strchr(format+2+strlen("pad:"), ',') + 1, 1)); + save = estrdup(ret); recursive = 1; - p = strdup(ui_format(NULL, content, hist)); + p = estrdup(ui_format(NULL, content, hist)); recursive = 0; memcpy(ret, save, rc); rc += snprintf(&ret[rc], sizeof(ret) - rc, "%1$*2$s", p, pn); @@ -1491,10 +1491,10 @@ ui_format(struct Window *window, char *format, struct History *hist) { } if (hist && !recursive && strncmp(content, "nick:", strlen("nick:")) == 0) { - content = strdup(ui_format_get_content(format+2+strlen("nick:"), 1)); - save = strdup(ret); /* save ret, as this will be modified by recursing */ + content = estrdup(ui_format_get_content(format+2+strlen("nick:"), 1)); + save = estrdup(ret); /* save ret, as this will be modified by recursing */ recursive = 1; - p = strdup(ui_format(NULL, content, hist)); + p = estrdup(ui_format(NULL, content, hist)); recursive = 0; memcpy(ret, save, rc); /* copy saved value back into ret, we don't need strlcpy as we don't use null byte */ @@ -1536,12 +1536,12 @@ ui_format(struct Window *window, char *format, struct History *hist) { ret[rc] = '\0'; if (!recursive && divider && !rhs) { - save = strdup(ret); + save = estrdup(ret); rc = snprintf(ret, sizeof(ret), "%1$*4$s%2$s%3$s", "", config_gets("divider.string"), save, config_getl("divider.margin")); free(save); } - save = strdup(ret); + save = estrdup(ret); rc = snprintf(ret, sizeof(ret), "%s%s", ts, save); free(save); @@ -1579,7 +1579,7 @@ ui_format(struct Window *window, char *format, struct History *hist) { } if (pc == window->w) { - save = strdup(p); + save = estrdup(p); if (divider) { p += snprintf(p, sizeof(ret) - ((size_t)(p - ret)), "%1$*4$s %2$s%3$s", @@ -1634,7 +1634,7 @@ ui_rectrl(char *str) { if (caret) ret[rc++] = '^'; ret[rc] = '\0'; - rp = strdup(ret); + rp = estrdup(ret); return rp; } @@ -1660,7 +1660,7 @@ ui_unctrl(char *str) { } ret[rc] = '\0'; - rp = strdup(ret); + rp = estrdup(ret); return rp; } @@ -1673,14 +1673,14 @@ ui_bind(char *binding, char *cmd) { if (!binding || !cmd) return -1; - p = malloc(sizeof(struct Keybind)); - p->binding = strdup(ui_rectrl(binding)); + p = emalloc(sizeof(struct Keybind)); + p->binding = estrdup(ui_rectrl(binding)); if (*cmd != '/') { - tmp = malloc(strlen(cmd) + 2); + tmp = emalloc(strlen(cmd) + 2); snprintf(tmp, strlen(cmd) + 2, "/%s", cmd); p->cmd = tmp; } else { - p->cmd = strdup(cmd); + p->cmd = estrdup(cmd); } p->prev = NULL; p->next = keybinds;