Skip to content

Commit 089af18

Browse files
committed
patch 7.4.891
Problem: Indentation of array initializer is wrong. Solution: Avoid that calling find_start_rawstring() changes the position returned by find_start_comment(), add a test. (Hirohito Higashi)
1 parent 094454f commit 089af18

4 files changed

Lines changed: 65 additions & 4 deletions

File tree

src/misc1.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5345,8 +5345,19 @@ find_start_comment(ind_maxcomment) /* XXX */
53455345
static pos_T *
53465346
ind_find_start_CORS() /* XXX */
53475347
{
5348-
pos_T *comment_pos = find_start_comment(curbuf->b_ind_maxcomment);
5349-
pos_T *rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment);
5348+
static pos_T comment_pos_copy;
5349+
pos_T *comment_pos;
5350+
pos_T *rs_pos;
5351+
5352+
comment_pos = find_start_comment(curbuf->b_ind_maxcomment);
5353+
if (comment_pos != NULL)
5354+
{
5355+
/* Need to make a copy of the static pos in findmatchlimit(),
5356+
* calling find_start_rawstring() may change it. */
5357+
comment_pos_copy = *comment_pos;
5358+
comment_pos = &comment_pos_copy;
5359+
}
5360+
rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment);
53505361

53515362
/* If comment_pos is before rs_pos the raw string is inside the comment.
53525363
* If rs_pos is before comment_pos the comment is inside the raw string. */
@@ -8334,7 +8345,8 @@ get_c_indent()
83348345
if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
83358346
&& terminated == ','))
83368347
{
8337-
if (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '[')
8348+
if (lookfor != LOOKFOR_ENUM_OR_INIT &&
8349+
(*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '['))
83388350
amount += ind_continuation;
83398351
/*
83408352
* if we're in the middle of a paren thing,
@@ -8576,7 +8588,10 @@ get_c_indent()
85768588
*/
85778589
l = ml_get_curline();
85788590
amount = cur_amount;
8579-
if (*skipwhite(l) == ']' || l[STRLEN(l) - 1] == ']')
8591+
8592+
n = (int)STRLEN(l);
8593+
if (terminated == ',' && (*skipwhite(l) == ']'
8594+
|| (n >=2 && l[n - 2] == ']')))
85808595
break;
85818596

85828597
/*

src/testdir/test3.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,28 @@ const char* s = R"foo(
910910
)foo";
911911
}
912912

913+
{
914+
int a[4] = {
915+
[0] = 0,
916+
[1] = 1,
917+
[2] = 2,
918+
[3] = 3,
919+
};
920+
}
921+
922+
{
923+
a = b[2]
924+
+ 3;
925+
}
926+
927+
{
928+
if (1)
929+
/* aaaaa
930+
* bbbbb
931+
*/
932+
a = 1;
933+
}
934+
913935
/* end of AUTO */
914936

915937
STARTTEST

src/testdir/test3.ok

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,28 @@ void getstring() {
898898
)foo";
899899
}
900900

901+
{
902+
int a[4] = {
903+
[0] = 0,
904+
[1] = 1,
905+
[2] = 2,
906+
[3] = 3,
907+
};
908+
}
909+
910+
{
911+
a = b[2]
912+
+ 3;
913+
}
914+
915+
{
916+
if (1)
917+
/* aaaaa
918+
* bbbbb
919+
*/
920+
a = 1;
921+
}
922+
901923
/* end of AUTO */
902924

903925

src/version.c

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

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
891,
744746
/**/
745747
890,
746748
/**/

0 commit comments

Comments
 (0)