# Vim

• R/O
• SSH

## vim: Commit

Mirror of the Vim source from https://github.com/vim/vim

### Commit MetaInfo

Revision 32bc4c71f8a6e5c0715709ca5f7eebcaeb156e62 (tree) 2023-12-01 02:30:03 Christian Brabandt Christian Brabandt

### Log Message

patch 9.0.2138: Overflow logic requires long long

Commit: https://github.com/vim/vim/commit/fda700cb04612fe2f9301a9ba820309175decabf
Author: Ernie Rael <errael@raelity.com>
Date: Thu Nov 30 18:20:00 2023 +0100

patch 9.0.2138: Overflow logic requires long long
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>

### Incremental Difference

diff -r 8ef8da090c3b -r 32bc4c71f8a6 src/cindent.c
--- a/src/cindent.c Thu Nov 30 18:00:03 2023 +0100
+++ b/src/cindent.c Thu Nov 30 18:30:03 2023 +0100
 @@ -1730,7 +1730,7 @@ 1730 1730 char_u *p; 1731 1731 char_u *l; 1732 1732 char_u *digits; 1733 - long long n; 1733 + vimlong_T n; 1734 1734 int divider; 1735 1735 int fraction = 0; 1736 1736 int sw;
 @@ -1902,7 +1902,7 @@ 1902 1902 { 1903 1903 n *= sw; 1904 1904 if (divider) 1905 - n += ((long long)sw * fraction + divider / 2) / divider; 1905 + n += ((vimlong_T)sw * fraction + divider / 2) / divider; 1906 1906 } 1907 1907 ++p; 1908 1908 }
diff -r 8ef8da090c3b -r 32bc4c71f8a6 src/misc1.c
--- a/src/misc1.c Thu Nov 30 18:00:03 2023 +0100
+++ b/src/misc1.c Thu Nov 30 18:30:03 2023 +0100
 @@ -2843,7 +2843,7 @@ 2843 2843 2844 2844 // Return something that fits into an int. 2845 2845 int 2846 -trim_to_int(long long x) 2846 +trim_to_int(vimlong_T x) 2847 2847 { 2848 2848 return x > INT_MAX ? INT_MAX : x < INT_MIN ? INT_MIN : x; 2849 2849 }
diff -r 8ef8da090c3b -r 32bc4c71f8a6 src/ops.c
--- a/src/ops.c Thu Nov 30 18:00:03 2023 +0100
+++ b/src/ops.c Thu Nov 30 18:30:03 2023 +0100
 @@ -229,11 +229,11 @@ 229 229 int amount, 230 230 int call_changed_bytes) // call changed_bytes() 231 231 { 232 - long long count; 232 + vimlong_T count; 233 233 int i, j; 234 234 int sw_val = trim_to_int(get_sw_value_indent(curbuf)); 235 235 236 - count = (long long)get_indent(); // get current indent 236 + count = get_indent(); // get current indent 237 237 238 238 if (round) // round off indent 239 239 {
 @@ -249,18 +249,18 @@ 249 249 } 250 250 else 251 251 i += amount; 252 - count = (long long)i * (long long)sw_val; 252 + count = (vimlong_T)i * (vimlong_T)sw_val; 253 253 } 254 254 else // original vi indent 255 255 { 256 256 if (left) 257 257 { 258 - count -= (long long)sw_val * (long long)amount; 258 + count -= (vimlong_T)sw_val * (vimlong_T)amount; 259 259 if (count < 0) 260 260 count = 0; 261 261 } 262 262 else 263 - count += (long long)sw_val * (long long)amount; 263 + count += (vimlong_T)sw_val * (vimlong_T)amount; 264 264 } 265 265 266 266 // Set new indent
diff -r 8ef8da090c3b -r 32bc4c71f8a6 src/proto/misc1.pro
--- a/src/proto/misc1.pro Thu Nov 30 18:00:03 2023 +0100
+++ b/src/proto/misc1.pro Thu Nov 30 18:30:03 2023 +0100
 @@ -55,5 +55,5 @@ 55 55 void may_trigger_modechanged(void); 56 56 int vim_append_digit_int(int *value, int digit); 57 57 int vim_append_digit_long(long *value, int digit); 58 -int trim_to_int(long long x); 58 +int trim_to_int(vimlong_T x); 59 59 /* vim: set ft=c : */
diff -r 8ef8da090c3b -r 32bc4c71f8a6 src/version.c
--- a/src/version.c Thu Nov 30 18:00:03 2023 +0100
+++ b/src/version.c Thu Nov 30 18:30:03 2023 +0100
 @@ -705,6 +705,8 @@ 705 705 static int included_patches[] = 706 706 { /* Add new patch number below this line */ 707 707 /**/ 708 + 2138, 709 +/**/ 708 710 2137, 709 711 /**/ 710 712 2136,
diff -r 8ef8da090c3b -r 32bc4c71f8a6 src/vim.h
--- a/src/vim.h Thu Nov 30 18:00:03 2023 +0100
+++ b/src/vim.h Thu Nov 30 18:30:03 2023 +0100
 @@ -435,6 +435,12 @@ 435 435 */ 436 436 typedef unsigned int u8char_T; // int is 32 bits or more 437 437 438 +/* 439 + * The vimlong_T has sizeof(vimlong_T) >= 2 * sizeof(int). 440 + * One use is simple handling of overflow in int calculations. 441 + */ 442 +typedef long long vimlong_T; 443 + 438 444 #ifndef UNIX // For Unix this is included in os_unix.h 439 445 # include 440 446 # include