diff options
author | Ernie Rael <errael@raelity.com> | 2023-11-30 18:20:00 +0100 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-11-30 18:20:00 +0100 |
commit | fda700cb04612fe2f9301a9ba820309175decabf (patch) | |
tree | b704d6bc4f42405f5b6ead830637b4aa167a7de4 /src | |
parent | 72314bb85f56dabc56d59b135083a80f85eafbb7 (diff) |
patch 9.0.2138: Overflow logic requires long longv9.0.2138
Problem: Overflow logic requires long long
Solution: Define vimlong_T data type to make life easier
for porters
closes: #13598
Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/cindent.c | 4 | ||||
-rw-r--r-- | src/misc1.c | 2 | ||||
-rw-r--r-- | src/ops.c | 10 | ||||
-rw-r--r-- | src/proto/misc1.pro | 2 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim.h | 6 |
6 files changed, 17 insertions, 9 deletions
diff --git a/src/cindent.c b/src/cindent.c index a9b813f6d8..62894228b1 100644 --- a/src/cindent.c +++ b/src/cindent.c @@ -1730,7 +1730,7 @@ parse_cino(buf_T *buf) char_u *p; char_u *l; char_u *digits; - long long n; + vimlong_T n; int divider; int fraction = 0; int sw; @@ -1902,7 +1902,7 @@ parse_cino(buf_T *buf) { n *= sw; if (divider) - n += ((long long)sw * fraction + divider / 2) / divider; + n += ((vimlong_T)sw * fraction + divider / 2) / divider; } ++p; } diff --git a/src/misc1.c b/src/misc1.c index e83ec66f70..bf70e38478 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -2843,7 +2843,7 @@ vim_append_digit_long(long *value, int digit) // Return something that fits into an int. int -trim_to_int(long long x) +trim_to_int(vimlong_T x) { return x > INT_MAX ? INT_MAX : x < INT_MIN ? INT_MIN : x; } @@ -229,11 +229,11 @@ shift_line( int amount, int call_changed_bytes) // call changed_bytes() { - long long count; + vimlong_T count; int i, j; int sw_val = trim_to_int(get_sw_value_indent(curbuf)); - count = (long long)get_indent(); // get current indent + count = get_indent(); // get current indent if (round) // round off indent { @@ -249,18 +249,18 @@ shift_line( } else i += amount; - count = (long long)i * (long long)sw_val; + count = (vimlong_T)i * (vimlong_T)sw_val; } else // original vi indent { if (left) { - count -= (long long)sw_val * (long long)amount; + count -= (vimlong_T)sw_val * (vimlong_T)amount; if (count < 0) count = 0; } else - count += (long long)sw_val * (long long)amount; + count += (vimlong_T)sw_val * (vimlong_T)amount; } // Set new indent diff --git a/src/proto/misc1.pro b/src/proto/misc1.pro index c602b0ebeb..e76bf75d0f 100644 --- a/src/proto/misc1.pro +++ b/src/proto/misc1.pro @@ -55,5 +55,5 @@ void restore_v_event(dict_T *v_event, save_v_event_T *sve); void may_trigger_modechanged(void); int vim_append_digit_int(int *value, int digit); int vim_append_digit_long(long *value, int digit); -int trim_to_int(long long x); +int trim_to_int(vimlong_T x); /* vim: set ft=c : */ diff --git a/src/version.c b/src/version.c index 1476f981bd..81128a3de0 100644 --- a/src/version.c +++ b/src/version.c @@ -705,6 +705,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2138, +/**/ 2137, /**/ 2136, @@ -435,6 +435,12 @@ typedef unsigned short sattr_T; */ typedef unsigned int u8char_T; // int is 32 bits or more +/* + * The vimlong_T has sizeof(vimlong_T) >= 2 * sizeof(int). + * One use is simple handling of overflow in int calculations. + */ +typedef long long vimlong_T; + #ifndef UNIX // For Unix this is included in os_unix.h # include <stdio.h> # include <ctype.h> |