Skip to content

Commit 98b3f72

Browse files
authored
Fix boundscheck in unsetindex for SubArrays (#53475)
These had been copy-pasted incorrectly, and should throw an error if the indices are out of bounds.
1 parent a2be715 commit 98b3f72

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

base/subarray.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -412,19 +412,19 @@ end
412412

413413
function _unsetindex!(V::FastSubArray, i::Int)
414414
@inline
415-
@boundscheck checkbounds(Bool, V, i)
415+
@boundscheck checkbounds(V, i)
416416
@inbounds _unsetindex!(V.parent, _reindexlinear(V, i))
417417
return V
418418
end
419419
function _unsetindex!(V::FastSubArray{<:Any,1}, i::Int)
420420
@inline
421-
@boundscheck checkbounds(Bool, V, i)
421+
@boundscheck checkbounds(V, i)
422422
@inbounds _unsetindex!(V.parent, _reindexlinear(V, i))
423423
return V
424424
end
425425
function _unsetindex!(V::SubArray{T,N}, i::Vararg{Int,N}) where {T,N}
426426
@inline
427-
@boundscheck checkbounds(Bool, V, i...)
427+
@boundscheck checkbounds(V, i...)
428428
@inbounds _unsetindex!(V.parent, reindex(V.indices, i)...)
429429
return V
430430
end

test/subarray.jl

+2
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,8 @@ end
10621062
for i in eachindex(A)
10631063
@test !isassigned(A, i)
10641064
end
1065+
inds = eachindex(A)
1066+
@test_throws BoundsError Base._unsetindex!(A, last(inds) + oneunit(eltype(inds)))
10651067
end
10661068
@testset "dest IndexLinear, src IndexLinear" begin
10671069
for p in (fill(BigInt(2)), BigInt[1, 2], BigInt[1 2; 3 4])

0 commit comments

Comments
 (0)