From 328b442d0d84a515d7f3284abd10ed91de69b049 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Wed, 23 Jul 2008 19:23:12 +0200 Subject: [PATCH] Gracefully ignore negative values given to options in ~/.tigrc --- tig.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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; } -- 2.30.2