Skip to content

Commit 2ddb89f

Browse files
committed
patch 8.2.3403: memory leak for :retab with invalid argument
Problem: Memory leak for :retab with invalid argument. Solution: Free the memory. Make error messages consistent.
1 parent b7081e1 commit 2ddb89f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/indent.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ tabstop_set(char_u *var, int **array)
7070
{
7171
int n = atoi((char *)cp);
7272

73+
// Catch negative values, overflow and ridiculous big values.
7374
if (n < 0 || n > 9999)
7475
{
7576
semsg(_(e_invarg2), cp);
77+
vim_free(*array);
78+
*array = NULL;
7679
return FAIL;
7780
}
7881
(*array)[t++] = n;
@@ -1615,12 +1618,18 @@ ex_retab(exarg_T *eap)
16151618
else
16161619
new_ts_str = vim_strnsave(new_ts_str, eap->arg - new_ts_str);
16171620
#else
1618-
new_ts = getdigits(&(eap->arg));
1619-
if (new_ts < 0)
1621+
ptr = eap->arg;
1622+
new_ts = getdigits(&ptr);
1623+
if (new_ts < 0 && *eap->arg == '-')
16201624
{
16211625
emsg(_(e_positive));
16221626
return;
16231627
}
1628+
if (new_ts < 0 || new_ts > 9999)
1629+
{
1630+
semsg(_(e_invarg2), eap->arg);
1631+
return;
1632+
}
16241633
if (new_ts == 0)
16251634
new_ts = curbuf->b_p_ts;
16261635
#endif

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3403,
758760
/**/
759761
3402,
760762
/**/

0 commit comments

Comments
 (0)