Skip to content

Commit

Permalink
Confirm token equality, safer loop
Browse files Browse the repository at this point in the history
Using different variable to iterate to guarantee unchanged behaviour
if anything doesn't work as intended.
  • Loading branch information
danielzuncke committed Oct 17, 2023
1 parent 979c74d commit 4a08417
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/dfmt/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -1055,10 +1055,17 @@ private:

// Account for possible function literals in this array which offset
// the previously set index (pos). Fixes issue #432.
while(astInformation.indentInfoSortedByEndLocation[pos].endLocation !=
size_t newPos = pos;
while(astInformation.indentInfoSortedByEndLocation[newPos].endLocation <
tokens[index].index)
{
pos++;
newPos++;
}

if (astInformation.indentInfoSortedByEndLocation[newPos].endLocation ==
tokens[index].index)
{
pos = newPos;
}

auto indentInfo = astInformation.indentInfoSortedByEndLocation[pos];
Expand Down

0 comments on commit 4a08417

Please sign in to comment.