Skip to content

Commit

Permalink
Fix boundscheck in unsetindex for SubArrays (JuliaLang#53475)
Browse files Browse the repository at this point in the history
These had been copy-pasted incorrectly, and should throw an error if the
indices are out of bounds.
  • Loading branch information
jishnub authored and tecosaur committed Mar 4, 2024
1 parent 239dd5c commit 3ac254f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,19 +412,19 @@ end

function _unsetindex!(V::FastSubArray, i::Int)
@inline
@boundscheck checkbounds(Bool, V, i)
@boundscheck checkbounds(V, i)
@inbounds _unsetindex!(V.parent, _reindexlinear(V, i))
return V
end
function _unsetindex!(V::FastSubArray{<:Any,1}, i::Int)
@inline
@boundscheck checkbounds(Bool, V, i)
@boundscheck checkbounds(V, i)
@inbounds _unsetindex!(V.parent, _reindexlinear(V, i))
return V
end
function _unsetindex!(V::SubArray{T,N}, i::Vararg{Int,N}) where {T,N}
@inline
@boundscheck checkbounds(Bool, V, i...)
@boundscheck checkbounds(V, i...)
@inbounds _unsetindex!(V.parent, reindex(V.indices, i)...)
return V
end
Expand Down
2 changes: 2 additions & 0 deletions test/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,8 @@ end
for i in eachindex(A)
@test !isassigned(A, i)
end
inds = eachindex(A)
@test_throws BoundsError Base._unsetindex!(A, last(inds) + oneunit(eltype(inds)))
end
@testset "dest IndexLinear, src IndexLinear" begin
for p in (fill(BigInt(2)), BigInt[1, 2], BigInt[1 2; 3 4])
Expand Down

0 comments on commit 3ac254f

Please sign in to comment.