0
0
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:
Ernie Rael
2023-11-23 20:21:45 +01:00
committed by Christian Brabandt
parent df63da98d8
commit 2b0882fa65
5 changed files with 18 additions and 13 deletions

View File

@@ -1734,7 +1734,7 @@ parse_cino(buf_T *buf)
int divider;
int fraction = 0;
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
if (t > INT_MAX / 2)
@@ -1902,17 +1902,14 @@ parse_cino(buf_T *buf)
{
n *= sw;
if (divider)
n += (sw * fraction + divider / 2) / divider;
n += ((long long)sw * fraction + divider / 2) / divider;
}
++p;
}
if (l[1] == '-')
n = -n;
if (n > INT_MAX)
n = INT_MAX;
else if (n < INT_MIN)
n = INT_MIN;
n = trim_to_int(n);
// When adding an entry here, also update the default 'cinoptions' in
// doc/indent.txt, and add explanation for it!