mirror of
https://github.com/neovim/neovim.git
synced 2025-10-17 07:16:09 +00:00
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.
This commit is contained in:
@@ -135,9 +135,7 @@ char_u *parse_shape_opt(int what)
|
||||
p += len;
|
||||
if (!VIM_ISDIGIT(*p))
|
||||
return (char_u *)N_("E548: digit expected");
|
||||
int64_t digits = getdigits(&p);
|
||||
assert(digits <= INT_MAX);
|
||||
int n = (int)digits;
|
||||
int n = get_int_digits(&p);
|
||||
if (len == 3) { /* "ver" or "hor" */
|
||||
if (n == 0)
|
||||
return (char_u *)N_("E549: Illegal percentage");
|
||||
|
Reference in New Issue
Block a user