From: Jonas Fonseca Date: Wed, 23 Jul 2008 17:23:12 +0000 (+0200) Subject: Gracefully ignore negative values given to options in ~/.tigrc X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=328b442d0d84a515d7f3284abd10ed91de69b049;p=tig.git Gracefully ignore negative values given to options in ~/.tigrc --- diff --git a/tig.c b/tig.c index 8679025..5b7b1ea 100644 --- a/tig.c +++ b/tig.c @@ -1101,6 +1101,14 @@ static bool parse_bool(const char *s) !strcmp(s, "yes")) ? TRUE : FALSE; } +static int +parse_int(const char *s, int default_value, int min, int max) +{ + int value = atoi(s); + + return (value < min || value > max) ? default_value : value; +} + /* Wants: name = value */ static int option_set_command(int argc, char *argv[]) @@ -1146,17 +1154,17 @@ option_set_command(int argc, char *argv[]) } if (!strcmp(argv[0], "line-number-interval")) { - opt_num_interval = atoi(argv[2]); + opt_num_interval = parse_int(argv[2], opt_num_interval, 1, 1024); return OK; } if (!strcmp(argv[0], "author-width")) { - opt_author_cols = atoi(argv[2]); + opt_author_cols = parse_int(argv[2], opt_author_cols, 0, 1024); return OK; } if (!strcmp(argv[0], "tab-size")) { - opt_tab_size = atoi(argv[2]); + opt_tab_size = parse_int(argv[2], opt_tab_size, 1, 1024); return OK; }