Skip to content

Commit aaaf57d

Browse files
committed
patch 8.0.0305: invalid memory access when option has duplicate flag
Problem: Invalid memory access when option has duplicate flag. Solution: Correct pointer computation. (Dominique Pelle, closes #1442)
1 parent 1fb0d49 commit aaaf57d

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/option.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4954,7 +4954,7 @@ do_set(
49544954
if (flags & P_FLAGLIST)
49554955
{
49564956
/* Remove flags that appear twice. */
4957-
for (s = newval; *s; ++s)
4957+
for (s = newval; *s;)
49584958
{
49594959
/* if options have P_FLAGLIST and
49604960
* P_ONECOMMA such as 'whichwrap' */
@@ -4966,7 +4966,7 @@ do_set(
49664966
/* Remove the duplicated value and
49674967
* the next comma. */
49684968
STRMOVE(s, s + 2);
4969-
s -= 2;
4969+
continue;
49704970
}
49714971
}
49724972
else
@@ -4975,9 +4975,10 @@ do_set(
49754975
&& vim_strchr(s + 1, *s) != NULL)
49764976
{
49774977
STRMOVE(s, s + 1);
4978-
--s;
4978+
continue;
49794979
}
49804980
}
4981+
++s;
49814982
}
49824983
}
49834984

src/testdir/test_options.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ function! Test_whichwrap()
1313
set whichwrap+=h,l
1414
call assert_equal('b,s,h,l', &whichwrap)
1515

16+
set whichwrap=h,h
17+
call assert_equal('h', &whichwrap)
18+
19+
set whichwrap=h,h,h
20+
call assert_equal('h', &whichwrap)
21+
1622
set whichwrap&
1723
endfunction
1824

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
305,
767769
/**/
768770
304,
769771
/**/

0 commit comments

Comments
 (0)