Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

searchsorted causes segfault #85

Closed
dlfivefifty opened this issue Nov 28, 2019 · 1 comment
Closed

searchsorted causes segfault #85

dlfivefifty opened this issue Nov 28, 2019 · 1 comment

Comments

@dlfivefifty
Copy link
Member

julia> using OffsetArrays

julia> o = OffsetArray([2,2,3],-1:1)
3-element OffsetArray(::Array{Int64,1}, -1:1) with eltype Int64 with indices -1:1:
 
2
 2
 3

julia> searchsorted(o,1)
Segmentation fault: 11

Using the debugger reveals its a strange bug:

julia> @enter searchsorted(o,1)
In #searchsorted#6(lt, by, rev, order, , v, x) at sort.jl:296
>1  1%1 = (Base.Order.ord)(lt, by, rev, order)
 2%2 = (searchsorted)(v, x, %1)
 3  └──      return %2

About to run: (Base.Order.ord)(isless, identity, nothing, Base.Order.ForwardOrdering())
1|debug> n
ERROR: BoundsError: attempt to access 3-element OffsetArray(::Array{Int64,1}, -1:1) with eltype Int64 with indices -1:1 at index [9223372036854775807]
Stacktrace:
 [1] throw_boundserror(::OffsetArray{Int64,1,Array{Int64,1}}, ::Tuple{Int64}) at abstractarray.jl:538
 [2] checkbounds(::OffsetArray{Int64,1,Array{Int64,1}}, ::Tuple{Int64}) at abstractarray.jl:503
 [3] getindex(::OffsetArray{Int64,1,Array{Int64,1}}, ::Int64) at /Users/solver/.julia/packages/OffsetArrays/vIbpP/src/OffsetArrays.jl:135
 [4] searchsorted(::OffsetArray{Int64,1,Array{Int64,1}}, ::Int64, ::Int64, ::Int64, ::Base.Order.ForwardOrdering) at sort.jl:214
 [5] searchsorted(::OffsetArray{Int64,1,Array{Int64,1}}, ::Int64, ::Base.Order.ForwardOrdering) at sort.jl:294
 [6] #searchsorted#6(::typeof(isless), ::typeof(identity), ::Nothing, ::Base.Order.ForwardOrdering, ::typeof(searchsorted), ::OffsetArray{Int64,1,Array{Int64,1}}, ::Int64) at sort.jl:296
 [7] searchsorted(::OffsetArray{Int64,1,Array{Int64,1}}, ::Int64) at sort.jl:296

PS I want this to support offset BlockArrays: JuliaArrays/BlockArrays.jl#95

@dlfivefifty
Copy link
Member Author

Ahhh, it's actually a bug in searchsortedfirst due to the fact that

julia> (-2) >>> 1
9223372036854775807

Let me open a second issue in JuliaLang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant