From 3344cffe7bf77c984550c01f9405f4d757150d8a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 13 Sep 2019 18:15:09 -0700 Subject: getdigits: introduce `strict`, `def` parameters Problem: During a refactor long ago, we changed the `getdigits_*` familiy of functions to abort on overflow. But this is often wrong, because many of these codepaths are handling user input. Solution: Decide at each call-site whether to use "strict" mode. fix #5555 --- src/nvim/regexp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/regexp.c') diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 37d71699dd..97c410a647 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3110,10 +3110,10 @@ static int read_limits(long *minval, long *maxval) reverse = TRUE; } first_char = regparse; - *minval = getdigits_long(®parse); + *minval = getdigits_long(®parse, false, 0); if (*regparse == ',') { /* There is a comma */ if (ascii_isdigit(*++regparse)) - *maxval = getdigits_long(®parse); + *maxval = getdigits_long(®parse, false, MAX_LIMIT); else *maxval = MAX_LIMIT; } else if (ascii_isdigit(*first_char)) -- cgit From 6aae0e7c943267d2109ae20ec5086791c3b94a5e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 13 Sep 2019 18:51:13 -0700 Subject: lint --- src/nvim/regexp.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/nvim/regexp.c') diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 97c410a647..9bc7ef07eb 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -3105,23 +3105,26 @@ static int read_limits(long *minval, long *maxval) long tmp; if (*regparse == '-') { - /* Starts with '-', so reverse the range later */ + // Starts with '-', so reverse the range later. regparse++; reverse = TRUE; } first_char = regparse; *minval = getdigits_long(®parse, false, 0); - if (*regparse == ',') { /* There is a comma */ - if (ascii_isdigit(*++regparse)) + if (*regparse == ',') { // There is a comma. + if (ascii_isdigit(*++regparse)) { *maxval = getdigits_long(®parse, false, MAX_LIMIT); - else + } else { *maxval = MAX_LIMIT; - } else if (ascii_isdigit(*first_char)) - *maxval = *minval; /* It was \{n} or \{-n} */ - else - *maxval = MAX_LIMIT; /* It was \{} or \{-} */ - if (*regparse == '\\') - regparse++; /* Allow either \{...} or \{...\} */ + } + } else if (ascii_isdigit(*first_char)) { + *maxval = *minval; // It was \{n} or \{-n} + } else { + *maxval = MAX_LIMIT; // It was \{} or \{-} + } + if (*regparse == '\\') { + regparse++; // Allow either \{...} or \{...\} + } if (*regparse != '}') { sprintf((char *)IObuff, _("E554: Syntax error in %s{...}"), reg_magic == MAGIC_ALL ? "" : "\\"); -- cgit