hirc

IRC client
Log | Files | Refs

commit 66a143e8369852871a2bbdf7663a4bbf0799b8ed
parent c1000351f4e75dd5dc309558b7c9a2f5ce23166f
Author: hhvn <dev@hhvn.uk>
Date:   Tue, 12 Apr 2022 12:52:14 +0100

Use strisnum

Diffstat:
Msrc/commands.c | 18++++++++----------
Msrc/config.c | 4++--
Msrc/hirc.h | 2+-
Msrc/main.c | 4++--
4 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -1865,7 +1865,7 @@ command_close) { COMMAND( command_ignore) { struct Ignore *ign, *p; - char errbuf[BUFSIZ], *s, *format = NULL; + char errbuf[BUFSIZ], *format = NULL; size_t len; long id; int ret, raw = 0, i, regopt = 0, serv = 0; @@ -1904,15 +1904,13 @@ command_ignore) { } return; case opt_delete: - for (s = str; s && *s; s++) { - if (!isdigit(*s)) { - ui_error("invalid id: %s", str); - return; - } + if (!strisnum(str, 0)) { + ui_error("invalid id: %s", str); + return; } id = strtol(str, NULL, 10); - if (id > INT_MAX || id < INT_MIN) - goto idlarge; + if (!id || id > INT_MAX || id < INT_MIN) + goto idrange; for (p = ignores, i = 1; p; p = p->next, i++) { if (i == id) { if (i == 1) @@ -1928,8 +1926,8 @@ command_ignore) { return; } } -idlarge: - ui_error("id too large: %s", str); +idrange: + ui_error("id out of range: %s", str); return; case opt_format: if (strncmp(command_optarg, "format.", 7) == 0) { diff --git a/src/config.c b/src/config.c @@ -1437,9 +1437,9 @@ config_set(char *name, char *val) { tok[1] = strtok_r(NULL, " ", &save); tok[2] = strtok_r(NULL, " ", &save); - if (strisnum(tok[0]) && strisnum(tok[1]) && !tok[2]) + if (strisnum(tok[0], 1) && strisnum(tok[1], 1) && !tok[2]) config_setr(name, strtol(tok[0], NULL, 10), strtol(tok[1], NULL, 10)); - else if (strisnum(tok[0]) && !tok[1]) + else if (strisnum(tok[0], 1) && !tok[1]) config_setl(name, strtol(tok[0], NULL, 10)); else if (tok[0] && strcmp(tok[0], "true") == 0) config_setl(name, 1); diff --git a/src/hirc.h b/src/hirc.h @@ -51,7 +51,7 @@ int ircprintf(struct Server *server, char *format, ...); char * homepath(char *path); char chrcmp(char c, char *s); char * struntil(char *str, char until); -int strisnum(char *str); +int strisnum(char *str, int allowneg); char * strntok(char *str, char *sep, int n); char * strrdate(time_t secs); diff --git a/src/main.c b/src/main.c @@ -260,11 +260,11 @@ struntil(char *str, char until) { } int -strisnum(char *str) { +strisnum(char *str, int allowneg) { if (!str) return 0; - if (*str == '-' || *str == '+') + if ((allowneg && *str == '-') || *str == '+') str += 1; for (; *str; str++)