aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_docmd.c
diff options
context:
space:
mode:
authorEliseo Martínez <eliseomarmol@gmail.com>2015-01-11 12:55:38 +0100
committerEliseo Martínez <eliseomarmol@gmail.com>2015-01-11 17:18:39 +0100
commit04c0658024a98a0586997f0ea8af1e3f774cc83e (patch)
treecb34605b25e040a179de11dbc34cc739c7547d34 /src/nvim/ex_docmd.c
parent28e75d4c453dcf7b1d1630815036d0236cfa0034 (diff)
downloadrneovim-04c0658024a98a0586997f0ea8af1e3f774cc83e.tar.gz
rneovim-04c0658024a98a0586997f0ea8af1e3f774cc83e.tar.bz2
rneovim-04c0658024a98a0586997f0ea8af1e3f774cc83e.zip
Cleanup: Refactor getdigits().
Problem : getdigits() currently returns a long, but at most places, return value is casted (unsafely) into an int. Making casts safe would introduce a lot of fuss in the form of assertions checking for limits. Note : We cannot just change return type to int, because, at some places, legitimate long values are used. For example, in diff.c, for line numbers. Solution : Introduce new functions: - get_digits() : Gets an intmax_t from a string. - get_int_digits() : Wrapper for ints. - get_long_digits() : Wrapper for longs. And replace getdigits() invocations by the appropiate wrapper invocations.
Diffstat (limited to 'src/nvim/ex_docmd.c')
-rw-r--r--src/nvim/ex_docmd.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index ca79270fcc..abc205a1e8 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -1733,7 +1733,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
if ((ea.argt & COUNT) && VIM_ISDIGIT(*ea.arg)
&& (!(ea.argt & BUFNAME) || *(p = skipdigits(ea.arg)) == NUL
|| vim_iswhite(*p))) {
- n = getdigits(&ea.arg);
+ n = get_long_digits(&ea.arg);
ea.arg = skipwhite(ea.arg);
if (n <= 0 && !ni && (ea.argt & ZEROR) == 0) {
errormsg = (char_u *)_(e_zerocount);
@@ -3250,7 +3250,7 @@ get_address (
default:
if (VIM_ISDIGIT(*cmd)) /* absolute line number */
- lnum = getdigits(&cmd);
+ lnum = get_long_digits(&cmd);
}
for (;; ) {
@@ -3267,7 +3267,7 @@ get_address (
if (!VIM_ISDIGIT(*cmd)) /* '+' is '+1', but '+0' is not '+1' */
n = 1;
else
- n = getdigits(&cmd);
+ n = get_long_digits(&cmd);
if (i == '-')
lnum -= n;
else
@@ -4439,7 +4439,7 @@ two_count:
return FAIL;
}
- *def = getdigits(&p);
+ *def = get_long_digits(&p);
*argt |= (ZEROR | NOTADR);
if (p != val + vallen || vallen == 0) {
@@ -4456,7 +4456,7 @@ invalid_count:
if (*def >= 0)
goto two_count;
- *def = getdigits(&p);
+ *def = get_long_digits(&p);
if (p != val + vallen)
goto invalid_count;
@@ -5819,7 +5819,7 @@ static void ex_tabmove(exarg_T *eap)
return;
}
- tab_number = getdigits(&p);
+ tab_number = get_int_digits(&p);
if (relative != 0)
tab_number = tab_number * relative + tabpage_index(curtab) - 1; ;
} else if (eap->addr_count != 0)
@@ -6441,10 +6441,10 @@ static void ex_winsize(exarg_T *eap)
char_u *arg = eap->arg;
char_u *p;
- w = getdigits(&arg);
+ w = get_int_digits(&arg);
arg = skipwhite(arg);
p = arg;
- h = getdigits(&arg);
+ h = get_int_digits(&arg);
if (*p != NUL && *arg == NUL)
screen_resize(w, h, TRUE);
else
@@ -6494,10 +6494,10 @@ static void ex_winpos(exarg_T *eap)
if (*arg == NUL) {
EMSG(_("E188: Obtaining window position not implemented for this platform"));
} else {
- x = getdigits(&arg);
+ x = get_int_digits(&arg);
arg = skipwhite(arg);
p = arg;
- y = getdigits(&arg);
+ y = get_int_digits(&arg);
if (*p == NUL || *arg != NUL) {
EMSG(_("E466: :winpos requires two number arguments"));
return;
@@ -6744,7 +6744,7 @@ static void ex_later(exarg_T *eap)
if (*p == NUL)
count = 1;
else if (isdigit(*p)) {
- count = getdigits(&p);
+ count = get_long_digits(&p);
switch (*p) {
case 's': ++p; sec = TRUE; break;
case 'm': ++p; sec = TRUE; count *= 60; break;
@@ -7354,7 +7354,7 @@ static void ex_findpat(exarg_T *eap)
n = 1;
if (vim_isdigit(*eap->arg)) { /* get count */
- n = getdigits(&eap->arg);
+ n = get_long_digits(&eap->arg);
eap->arg = skipwhite(eap->arg);
}
if (*eap->arg == '/') { /* Match regexp, not just whole words */
@@ -7618,7 +7618,7 @@ eval_vars (
s = src + 1;
if (*s == '<') /* "#<99" uses v:oldfiles */
++s;
- i = (int)getdigits(&s);
+ i = get_int_digits(&s);
*usedlen = (int)(s - src); /* length of what we expand */
if (src[1] == '<') {