mirror of
https://github.com/vim/vim.git
synced 2025-10-08 06:04:08 -04:00
patch 9.0.2124: INT overflow detection logic can be simplified
Problem: INT overflow logic can be simplified Solution: introduce trim_to_int() function closes: #13556 Signed-off-by: Ernie Rael <errael@raelity.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
df63da98d8
commit
2b0882fa65
@@ -1734,7 +1734,7 @@ parse_cino(buf_T *buf)
|
|||||||
int divider;
|
int divider;
|
||||||
int fraction = 0;
|
int fraction = 0;
|
||||||
int sw;
|
int sw;
|
||||||
long long t = get_sw_value(buf);
|
long t = get_sw_value(buf);
|
||||||
|
|
||||||
// needed for cino-(, it will be multiplied by 2 again
|
// needed for cino-(, it will be multiplied by 2 again
|
||||||
if (t > INT_MAX / 2)
|
if (t > INT_MAX / 2)
|
||||||
@@ -1902,17 +1902,14 @@ parse_cino(buf_T *buf)
|
|||||||
{
|
{
|
||||||
n *= sw;
|
n *= sw;
|
||||||
if (divider)
|
if (divider)
|
||||||
n += (sw * fraction + divider / 2) / divider;
|
n += ((long long)sw * fraction + divider / 2) / divider;
|
||||||
}
|
}
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
if (l[1] == '-')
|
if (l[1] == '-')
|
||||||
n = -n;
|
n = -n;
|
||||||
|
|
||||||
if (n > INT_MAX)
|
n = trim_to_int(n);
|
||||||
n = INT_MAX;
|
|
||||||
else if (n < INT_MIN)
|
|
||||||
n = INT_MIN;
|
|
||||||
|
|
||||||
// When adding an entry here, also update the default 'cinoptions' in
|
// When adding an entry here, also update the default 'cinoptions' in
|
||||||
// doc/indent.txt, and add explanation for it!
|
// doc/indent.txt, and add explanation for it!
|
||||||
|
@@ -2838,3 +2838,11 @@ vim_append_digit_long(long *value, int digit)
|
|||||||
*value = x * 10 + (long)digit;
|
*value = x * 10 + (long)digit;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return something that fits into an int.
|
||||||
|
int
|
||||||
|
trim_to_int(long long x)
|
||||||
|
{
|
||||||
|
return x > INT_MAX ? INT_MAX : x < INT_MIN ? INT_MIN : x;
|
||||||
|
}
|
||||||
|
|
||||||
|
11
src/ops.c
11
src/ops.c
@@ -230,8 +230,8 @@ shift_line(
|
|||||||
int call_changed_bytes) // call changed_bytes()
|
int call_changed_bytes) // call changed_bytes()
|
||||||
{
|
{
|
||||||
long long count;
|
long long count;
|
||||||
long i, j;
|
int i, j;
|
||||||
long sw_val = get_sw_value_indent(curbuf);
|
int sw_val = trim_to_int(get_sw_value_indent(curbuf));
|
||||||
|
|
||||||
count = (long long)get_indent(); // get current indent
|
count = (long long)get_indent(); // get current indent
|
||||||
|
|
||||||
@@ -263,14 +263,11 @@ shift_line(
|
|||||||
count += (long long)sw_val * (long long)amount;
|
count += (long long)sw_val * (long long)amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > INT_MAX)
|
|
||||||
count = INT_MAX;
|
|
||||||
|
|
||||||
// Set new indent
|
// Set new indent
|
||||||
if (State & VREPLACE_FLAG)
|
if (State & VREPLACE_FLAG)
|
||||||
change_indent(INDENT_SET, (int)count, FALSE, NUL, call_changed_bytes);
|
change_indent(INDENT_SET, trim_to_int(count), FALSE, NUL, call_changed_bytes);
|
||||||
else
|
else
|
||||||
(void)set_indent((int)count, call_changed_bytes ? SIN_CHANGED : 0);
|
(void)set_indent(trim_to_int(count), call_changed_bytes ? SIN_CHANGED : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -55,4 +55,5 @@ void restore_v_event(dict_T *v_event, save_v_event_T *sve);
|
|||||||
void may_trigger_modechanged(void);
|
void may_trigger_modechanged(void);
|
||||||
int vim_append_digit_int(int *value, int digit);
|
int vim_append_digit_int(int *value, int digit);
|
||||||
int vim_append_digit_long(long *value, int digit);
|
int vim_append_digit_long(long *value, int digit);
|
||||||
|
int trim_to_int(long long x);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
@@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2124,
|
||||||
/**/
|
/**/
|
||||||
2123,
|
2123,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user