patch 9.0.2138: Overflow logic requires long long

Commit: 
https://github.com/vim/vim/commit/fda700cb04612fe2f9301a9ba820309175decabf
Author: Ernie Rael <err...@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 <err...@raelity.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/cindent.c b/src/cindent.c
index a9b813f6d..62894228b 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 e83ec66f7..bf70e3847 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;
 }
diff --git a/src/ops.c b/src/ops.c
index e30fea7e0..46101a435 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -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 c602b0ebe..e76bf75d0 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 1476f981b..81128a3de 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2138,
 /**/
     2137,
 /**/
diff --git a/src/vim.h b/src/vim.h
index 6fb897822..7d0d128ae 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -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>

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1r8krT-008pN8-MD%40256bit.org.

Raspunde prin e-mail lui