From 82061b1202a81cef0bb4874e6a093cda56822f02 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Mon, 26 Sep 2022 08:39:59 +0100 Subject: [PATCH] [bugfix] panic during child thread iteration (#852) * *actually* start at top of stack loop on find remote child, fix iter indexing Signed-off-by: kim * add improved code comment Signed-off-by: kim Signed-off-by: kim --- internal/federation/dereferencing/thread.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/federation/dereferencing/thread.go b/internal/federation/dereferencing/thread.go index d15f05964..7626454a6 100644 --- a/internal/federation/dereferencing/thread.go +++ b/internal/federation/dereferencing/thread.go @@ -235,11 +235,11 @@ type frame struct { // Start off the item iterator current.itemIter = items.Begin() - current.iterIdx = -1 + current.iterIdx = 0 } itemLoop: - for current.iterIdx++; current.iterIdx < current.iterLen; current.iterIdx++ { + for ; current.iterIdx < current.iterLen; current.iterIdx++ { var itemIRI *url.URL // Get next item iterator object @@ -275,11 +275,21 @@ type frame struct { continue itemLoop } + // Iter past this item. Normally this would be + // handled by the third clause of the itemLoop's + // embedded range checking, but at the bottom of this + // loop since we found a new status we circle back to + // the beginning of the stackLoop and skip iteration. + current.iterIdx++ + // Put current and next frame at top of stack stack = append(stack, current, &frame{ statusIRI: itemIRI, statusable: statusable, }) + + // Now start at top of loop + continue stackLoop } // Item iterator is done