From 08fe5d6855615b5bed530a3f9c3bf36f77c5ffda Mon Sep 17 00:00:00 2001 From: Daniel Zuncke Date: Tue, 17 Oct 2023 20:24:02 +0200 Subject: [PATCH] Confirm token equality, safer loop Using different variable to iterate to guarantee unchanged behaviour if anything doesn't work as intended. --- src/dfmt/formatter.d | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index f76e6e2..8ea8cc6 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -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];