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/digraph.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 2b5fdea2fe..7a24203594 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1611,9 +1611,7 @@ void putdigraph(char_u *str) EMSG(_(e_number_exp)); return; } - int64_t digits = getdigits(&str); - assert(digits <= INT_MAX); - int n = (int)digits; + int n = get_int_digits(&str); // If the digraph already exists, replace the result. dp = (digr_T *)user_digraphs.ga_data; -- cgit From 7f7262e93390a1855ac9c687bd492eadfe10cf98 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 11 Jan 2015 20:57:33 +0100 Subject: Cleanup: Rename getdigits() family functions. --- src/nvim/digraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/digraph.c') diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 7a24203594..243468b680 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1611,7 +1611,7 @@ void putdigraph(char_u *str) EMSG(_(e_number_exp)); return; } - int n = get_int_digits(&str); + int n = getdigits_int(&str); // If the digraph already exists, replace the result. dp = (digr_T *)user_digraphs.ga_data; -- cgit