diff options
author | Eliseo Martínez <eliseomarmol@gmail.com> | 2015-01-11 12:55:38 +0100 |
---|---|---|
committer | Eliseo Martínez <eliseomarmol@gmail.com> | 2015-01-11 17:18:39 +0100 |
commit | 04c0658024a98a0586997f0ea8af1e3f774cc83e (patch) | |
tree | cb34605b25e040a179de11dbc34cc739c7547d34 /src/nvim/option.c | |
parent | 28e75d4c453dcf7b1d1630815036d0236cfa0034 (diff) | |
download | rneovim-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/option.c')
-rw-r--r-- | src/nvim/option.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 20e983b253..2c9bd58d08 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2918,7 +2918,7 @@ do_set ( */ else if (varp == (char_u *)&p_bs && VIM_ISDIGIT(**(char_u **)varp)) { - i = getdigits((char_u **)varp); + i = get_int_digits((char_u **)varp); switch (i) { case 0: *(char_u **)varp = empty_option; @@ -2943,7 +2943,7 @@ do_set ( else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(*arg)) { *errbuf = NUL; - i = getdigits(&arg); + i = get_int_digits(&arg); if (i & 1) STRCAT(errbuf, "b,"); if (i & 2) @@ -4359,7 +4359,7 @@ did_set_string_option ( /* set ru_wid if 'ruf' starts with "%99(" */ if (*++s == '-') /* ignore a '-' */ s++; - wid = getdigits(&s); + wid = get_int_digits(&s); if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL) ru_wid = wid; else @@ -4664,14 +4664,14 @@ char_u *check_colorcolumn(win_T *wp) ++s; if (!VIM_ISDIGIT(*s)) return e_invarg; - col = col * getdigits(&s); + col = col * get_int_digits(&s); if (wp->w_buffer->b_p_tw == 0) goto skip; /* 'textwidth' not set, skip this item */ col += wp->w_buffer->b_p_tw; if (col < 0) goto skip; } else if (VIM_ISDIGIT(*s)) - col = getdigits(&s); + col = get_int_digits(&s); else return e_invarg; color_cols[count++] = col - 1; /* 1-based to 0-based */ @@ -8114,12 +8114,12 @@ static bool briopt_check(win_T *wp) && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6]))) { p += 6; - bri_shift = getdigits(&p); + bri_shift = get_int_digits(&p); } else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4])) { p += 4; - bri_min = getdigits(&p); + bri_min = get_long_digits(&p); } else if (STRNCMP(p, "sbr", 3) == 0) { |