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/term.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/term.c')
-rw-r--r-- | src/nvim/term.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/nvim/term.c b/src/nvim/term.c index dfc42632c6..8e4efd69fb 100644 --- a/src/nvim/term.c +++ b/src/nvim/term.c @@ -3230,7 +3230,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) */ p = tp + slen; - mouse_code = getdigits(&p); + mouse_code = get_long_digits(&p); if (*p++ != ';') return -1; @@ -3238,15 +3238,11 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) if (key_name[0] == KS_SGR_MOUSE) mouse_code += 32; - long digits = getdigits(&p); - assert(digits >= INT_MIN && digits <= INT_MAX); - mouse_col = (int)digits - 1; + mouse_col = get_int_digits(&p); if (*p++ != ';') return -1; - digits = getdigits(&p); - assert(digits >= INT_MIN && digits <= INT_MAX); - mouse_row = (int)digits - 1; + mouse_row = get_int_digits(&p); if (key_name[0] == KS_SGR_MOUSE && *p == 'm') mouse_code |= MOUSE_RELEASE; else if (*p != 'M') @@ -3273,7 +3269,7 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) } } p += j; - if (cmd_complete && getdigits(&p) == mouse_code) { + if (cmd_complete && get_long_digits(&p) == mouse_code) { slen += j; /* skip the \033[ */ continue; } @@ -3319,10 +3315,10 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) * '6' is the row, 45 is the column */ p = tp + slen; - mr = getdigits(&p); + mr = get_long_digits(&p); if (*p++ != ',') return -1; - mc = getdigits(&p); + mc = get_long_digits(&p); if (*p++ != '\r') return -1; @@ -3389,27 +3385,27 @@ int check_termcode(int max_offset, char_u *buf, int bufsize, int *buflen) p = tp + slen; /* get event status */ - Pe = getdigits(&p); + Pe = get_long_digits(&p); if (*p++ != ';') return -1; /* get button status */ - Pb = getdigits(&p); + Pb = get_long_digits(&p); if (*p++ != ';') return -1; /* get row status */ - Pr = getdigits(&p); + Pr = get_long_digits(&p); if (*p++ != ';') return -1; /* get column status */ - Pc = getdigits(&p); + Pc = get_long_digits(&p); /* the page parameter is optional */ if (*p == ';') { p++; - (void)getdigits(&p); + (void)get_long_digits(&p); } if (*p++ != '&') return -1; |