aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/buffer.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/buffer.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/buffer.c')
-rw-r--r--src/nvim/buffer.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 4c40cd631e..5c1b01130d 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -750,7 +750,7 @@ do_bufdel (
break;
arg = p;
} else
- bnr = getdigits(&arg);
+ bnr = get_int_digits(&arg);
}
}
if (!got_int && do_current && do_buffer(command, DOBUF_FIRST,
@@ -2997,7 +2997,7 @@ build_stl_str_hl (
l = -1;
}
if (VIM_ISDIGIT(*s)) {
- minwid = (int)getdigits(&s);
+ minwid = get_int_digits(&s);
if (minwid < 0) /* overflow */
minwid = 0;
}
@@ -3033,7 +3033,7 @@ build_stl_str_hl (
if (*s == '.') {
s++;
if (VIM_ISDIGIT(*s)) {
- maxwid = (int)getdigits(&s);
+ maxwid = get_int_digits(&s);
if (maxwid <= 0) /* overflow */
maxwid = 50;
}
@@ -4077,7 +4077,7 @@ chk_modeline (
e = s + 4;
else
e = s + 3;
- vers = getdigits(&e);
+ vers = get_int_digits(&e);
if (*e == ':'
&& (s[0] != 'V'
|| STRNCMP(skipwhite(e + 1), "set", 3) == 0)