From 04c0658024a98a0586997f0ea8af1e3f774cc83e Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 11 Jan 2015 12:55:38 +0100 Subject: 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. --- src/nvim/indent_c.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/nvim/indent_c.c') diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 39ad512227..94d2a2ffff 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -1463,9 +1463,7 @@ void parse_cino(buf_T *buf) if (*p == '-') ++p; char_u *digits_start = p; /* remember where the digits start */ - int64_t digits = getdigits(&p); - assert(digits <= INT_MAX); - int n = (int)digits; + int n = get_int_digits(&p); divider = 0; if (*p == '.') { /* ".5s" means a fraction */ fraction = atoi((char *)++p); @@ -1678,9 +1676,7 @@ int get_c_indent(void) else if (*p == COM_LEFT || *p == COM_RIGHT) align = *p++; else if (VIM_ISDIGIT(*p) || *p == '-') { - int64_t digits = getdigits(&p); - assert(digits <= INT_MAX); - off = (int)digits; + off = get_int_digits(&p); } else ++p; -- cgit