Skip to content

Commit

Permalink
fix off-by-1 in stacktrace lookup code (#27524)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored and vtjnash committed Jun 11, 2018
1 parent 2ba3fbb commit b226d79
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/stacktraces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function lookup(ip::Base.InterpreterIP)
file = empty_sym
line = 0
end
i = max(ip.stmt, 1)
i = max(ip.stmt+1, 1) # ip.stmt is 0-indexed
if i > length(codeinfo.codelocs) || codeinfo.codelocs[i] == 0
return [StackFrame(func, file, line, ip.code, false, false, 0)]
end
Expand Down
12 changes: 12 additions & 0 deletions test/stacktraces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,15 @@ trace = StackTracesTestMod.unfiltered_stacktrace()

trace = StackTracesTestMod.filtered_stacktrace()
@test !occursin("filtered_stacktrace", string(trace))

let bt, topline = @__LINE__
try
let x = 1
y = 2x
z = 2z-1
end
catch
bt = stacktrace(catch_backtrace())
end
@test bt[1].line == topline+4
end

0 comments on commit b226d79

Please sign in to comment.