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

Don't access uninitialized indices in tril!/triu! for numeric arrays #52528

Merged
merged 9 commits into from
Jan 25, 2024
Prev Previous commit
Next Next commit
Assign zero individually
  • Loading branch information
jishnub committed Dec 14, 2023
commit 1d8e5abd5c519d3bc474b1bdd90640c9e83315d2
6 changes: 2 additions & 4 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ function triu!(M::AbstractMatrix, k::Integer)
end
function _triu!(M::AbstractMatrix{<:Number}, k::Integer)
m, n = size(M)
z = zero(eltype(M))
for j in 1:min(n, m + k)
for i in max(1, j - k + 1):m
@inbounds M[i,j] = z
@inbounds M[i,j] = zero(eltype(M))
end
end
return M
Expand Down Expand Up @@ -188,10 +187,9 @@ function tril!(M::AbstractMatrix, k::Integer)
end
function _tril!(M::AbstractMatrix{<:Number}, k)
m, n = size(M)
z = zero(eltype(M))
for j in max(1, k + 1):n
for i in 1:min(j - k - 1, m)
@inbounds M[i,j] = z
@inbounds M[i,j] = zero(eltype(M))
end
end
return M
Expand Down