From 22e7e2437fb2654eb8764474767d6aa2947a1ab7 Mon Sep 17 00:00:00 2001 From: Fred Callaway Date: Tue, 20 Jul 2021 00:25:43 -0700 Subject: [PATCH] while loop -> for loop in _simplify_include_frames (fixes #41566) (#41622) * while loop -> for loop in _simplify_include_frames (fixes #41566) prevents the possibility of a bounds error when i = 0 (cherry picked from commit ed4f3169573903f1767871243375d2407db959a0) --- base/errorshow.jl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/base/errorshow.jl b/base/errorshow.jl index 49fe9680e180d..e8153cd191e86 100644 --- a/base/errorshow.jl +++ b/base/errorshow.jl @@ -788,10 +788,9 @@ end # For improved user experience, filter out frames for include() implementation # - see #33065. See also #35371 for extended discussion of internal frames. function _simplify_include_frames(trace) - i = length(trace) - kept_frames = trues(i) + kept_frames = trues(length(trace)) first_ignored = nothing - while i >= 1 + for i in length(trace):-1:1 frame::StackFrame, _ = trace[i] mod = parentmodule(frame) if first_ignored === nothing @@ -813,10 +812,9 @@ function _simplify_include_frames(trace) first_ignored = nothing end end - i -= 1 end if first_ignored !== nothing - kept_frames[i:first_ignored] .= false + kept_frames[1:first_ignored] .= false end return trace[kept_frames] end