Skip to content

Commit c69cae3

Browse files
committed
Merge pull request #11625 from JuliaLang/mb/unsafersub
Ensure SubArray's unsafe_getindex doesn't check bounds
2 parents 7c1140f + fc8aa93 commit c69cae3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

base/subarray.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,9 @@ getindex(V::SubArray, I::Int...) = (@_inline_meta; checkbounds(V, I...); unsafe_
533533
if ni == 1 && length(IV.parameters) == LD # linear indexing
534534
meta = Expr(:meta, :inline)
535535
if iscontiguous(V)
536-
return :($meta; V.parent[V.first_index + I[1] - 1])
536+
return :($meta; unsafe_getindex(V.parent, V.first_index + I[1] - 1))
537537
end
538-
return :($meta; V.parent[V.first_index + V.stride1*(I[1]-1)])
538+
return :($meta; unsafe_getindex(V.parent, V.first_index + V.stride1*(I[1]-1)))
539539
end
540540
Isyms = [:(I[$d]) for d = 1:ni]
541541
exhead, idxs = index_generate(ndims(P), IV, :V, Isyms)
@@ -550,9 +550,9 @@ setindex!(V::SubArray, v, I::Int...) = (@_inline_meta; checkbounds(V, I...); uns
550550
if ni == 1 && length(IV.parameters) == LD # linear indexing
551551
meta = Expr(:meta, :inline)
552552
if iscontiguous(V)
553-
return :($meta; V.parent[V.first_index + I[1] - 1] = v)
553+
return :($meta; unsafe_setindex!(V.parent, v, V.first_index + I[1] - 1))
554554
end
555-
return :($meta; V.parent[V.first_index + V.stride1*(I[1]-1)] = v)
555+
return :($meta; unsafe_setindex!(V.parent, v, V.first_index + V.stride1*(I[1]-1)))
556556
end
557557
Isyms = [:(I[$d]) for d = 1:ni]
558558
exhead, idxs = index_generate(ndims(P), IV, :V, Isyms)

0 commit comments

Comments
 (0)