• R/O
  • SSH

vim: Commit

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


Commit MetaInfo

Revision32bc4c71f8a6e5c0715709ca5f7eebcaeb156e62 (tree)
Time2023-12-01 02:30:03
AuthorChristian Brabandt <cb@256b...>
CommiterChristian 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>

Change Summary

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 @@
17301730 char_u *p;
17311731 char_u *l;
17321732 char_u *digits;
1733- long long n;
1733+ vimlong_T n;
17341734 int divider;
17351735 int fraction = 0;
17361736 int sw;
@@ -1902,7 +1902,7 @@
19021902 {
19031903 n *= sw;
19041904 if (divider)
1905- n += ((long long)sw * fraction + divider / 2) / divider;
1905+ n += ((vimlong_T)sw * fraction + divider / 2) / divider;
19061906 }
19071907 ++p;
19081908 }
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 @@
28432843
28442844 // Return something that fits into an int.
28452845 int
2846-trim_to_int(long long x)
2846+trim_to_int(vimlong_T x)
28472847 {
28482848 return x > INT_MAX ? INT_MAX : x < INT_MIN ? INT_MIN : x;
28492849 }
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 @@
229229 int amount,
230230 int call_changed_bytes) // call changed_bytes()
231231 {
232- long long count;
232+ vimlong_T count;
233233 int i, j;
234234 int sw_val = trim_to_int(get_sw_value_indent(curbuf));
235235
236- count = (long long)get_indent(); // get current indent
236+ count = get_indent(); // get current indent
237237
238238 if (round) // round off indent
239239 {
@@ -249,18 +249,18 @@
249249 }
250250 else
251251 i += amount;
252- count = (long long)i * (long long)sw_val;
252+ count = (vimlong_T)i * (vimlong_T)sw_val;
253253 }
254254 else // original vi indent
255255 {
256256 if (left)
257257 {
258- count -= (long long)sw_val * (long long)amount;
258+ count -= (vimlong_T)sw_val * (vimlong_T)amount;
259259 if (count < 0)
260260 count = 0;
261261 }
262262 else
263- count += (long long)sw_val * (long long)amount;
263+ count += (vimlong_T)sw_val * (vimlong_T)amount;
264264 }
265265
266266 // 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 @@
5555 void may_trigger_modechanged(void);
5656 int vim_append_digit_int(int *value, int digit);
5757 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);
5959 /* 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 @@
705705 static int included_patches[] =
706706 { /* Add new patch number below this line */
707707 /**/
708+ 2138,
709+/**/
708710 2137,
709711 /**/
710712 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 @@
435435 */
436436 typedef unsigned int u8char_T; // int is 32 bits or more
437437
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+
438444 #ifndef UNIX // For Unix this is included in os_unix.h
439445 # include <stdio.h>
440446 # include <ctype.h>
Show on old repository browser