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/spell.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/spell.c')
-rw-r--r-- | src/nvim/spell.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/nvim/spell.c b/src/nvim/spell.c index b8713909b8..af020198d3 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -5162,7 +5162,7 @@ static unsigned get_affitem(int flagtype, char_u **pp) ++*pp; // always advance, avoid getting stuck return 0; } - res = getdigits(pp); + res = get_int_digits(pp); } else { res = mb_ptr2char_adv(pp); if (flagtype == AFT_LONG || (flagtype == AFT_CAPLONG @@ -5283,7 +5283,9 @@ static bool flag_in_afflist(int flagtype, char_u *afflist, unsigned flag) case AFT_NUM: for (p = afflist; *p != NUL; ) { - n = getdigits(&p); + int digits = get_int_digits(&p); + assert(digits >= 0); + n = (unsigned int)digits; if (n == flag) return true; if (*p != NUL) // skip over comma @@ -6357,19 +6359,19 @@ int spell_check_msm(void) if (!VIM_ISDIGIT(*p)) return FAIL; // block count = (value * 1024) / SBLOCKSIZE (but avoid overflow) - start = (getdigits(&p) * 10) / (SBLOCKSIZE / 102); + start = (get_long_digits(&p) * 10) / (SBLOCKSIZE / 102); if (*p != ',') return FAIL; ++p; if (!VIM_ISDIGIT(*p)) return FAIL; - incr = (getdigits(&p) * 102) / (SBLOCKSIZE / 10); + incr = (get_long_digits(&p) * 102) / (SBLOCKSIZE / 10); if (*p != ',') return FAIL; ++p; if (!VIM_ISDIGIT(*p)) return FAIL; - added = getdigits(&p) * 1024; + added = get_long_digits(&p) * 1024; if (*p != NUL) return FAIL; @@ -8355,7 +8357,7 @@ int spell_check_sps(void) f = 0; if (VIM_ISDIGIT(*buf)) { s = buf; - sps_limit = getdigits(&s); + sps_limit = get_int_digits(&s); if (*s != NUL && !VIM_ISDIGIT(*s)) f = -1; } else if (STRCMP(buf, "best") == 0) |