0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

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>
This commit is contained in:
Ernie Rael 2023-11-30 18:20:00 +01:00 committed by Christian Brabandt
parent 72314bb85f
commit fda700cb04
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
6 changed files with 17 additions and 9 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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 : */

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2138,
/**/
2137,
/**/

View File

@ -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>