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/diff.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/diff.c')
-rw-r--r-- | src/nvim/diff.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 7e31c3f216..307ccadf5f 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1221,11 +1221,11 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname) // {first}a{first}[,{last}] // {first}[,{last}]d{first} p = linebuf; - f1 = getdigits(&p); + f1 = get_long_digits(&p); if (*p == ',') { ++p; - l1 = getdigits(&p); + l1 = get_long_digits(&p); } else { l1 = f1; } @@ -1235,11 +1235,11 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname) continue; } difftype = *p++; - f2 = getdigits(&p); + f2 = get_long_digits(&p); if (*p == ',') { ++p; - l2 = getdigits(&p); + l2 = get_long_digits(&p); } else { l2 = f2; } @@ -1783,7 +1783,7 @@ int diffopt_changed(void) diff_flags_new |= DIFF_FILLER; } else if ((STRNCMP(p, "context:", 8) == 0) && VIM_ISDIGIT(p[8])) { p += 8; - diff_context_new = getdigits(&p); + diff_context_new = get_int_digits(&p); } else if (STRNCMP(p, "icase", 5) == 0) { p += 5; diff_flags_new |= DIFF_ICASE; @@ -1798,7 +1798,7 @@ int diffopt_changed(void) diff_flags_new |= DIFF_VERTICAL; } else if ((STRNCMP(p, "foldcolumn:", 11) == 0) && VIM_ISDIGIT(p[11])) { p += 11; - diff_foldcolumn_new = getdigits(&p); + diff_foldcolumn_new = get_int_digits(&p); } if ((*p != ',') && (*p != NUL)) { |