From 98b3f721275082cbf3c1ece9d3ae394ec305e12f Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 27 Feb 2024 06:46:22 +0530 Subject: [PATCH] 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. --- base/subarray.jl | 6 +++--- test/subarray.jl | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/base/subarray.jl b/base/subarray.jl index c15a4d48868fa..2b8545c2cc226 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -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 diff --git a/test/subarray.jl b/test/subarray.jl index ada53d7d91ee3..31bd69cccb5ae 100644 --- a/test/subarray.jl +++ b/test/subarray.jl @@ -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])