Skip to content

Commit

Permalink
fix: aliasing bug in mul!
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Jan 6, 2025
1 parent be48dbf commit 2cedd31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/flint/gfp_fmpz_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,13 @@ end

function mul!(z::FpFieldElem, x::FpFieldElem, y::ZZRingElem)
R = parent(x)
@ccall libflint.fmpz_mod(z.data::Ref{ZZRingElem}, y::Ref{ZZRingElem}, R.n::Ref{ZZRingElem})::Nothing

@ccall libflint.fmpz_mod_mul(z.data::Ref{ZZRingElem}, x.data::Ref{ZZRingElem}, z.data::Ref{ZZRingElem}, R.ninv::Ref{fmpz_mod_ctx_struct})::Nothing
return z
if z !== x
@ccall libflint.fmpz_mod(z.data::Ref{ZZRingElem}, y::Ref{ZZRingElem}, R.n::Ref{ZZRingElem})::Nothing
@ccall libflint.fmpz_mod_mul(z.data::Ref{ZZRingElem}, x.data::Ref{ZZRingElem}, z.data::Ref{ZZRingElem}, R.ninv::Ref{fmpz_mod_ctx_struct})::Nothing
return z

Check warning on line 370 in src/flint/gfp_fmpz_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/gfp_fmpz_elem.jl#L368-L370

Added lines #L368 - L370 were not covered by tests
else
return mul!(z, x, R(y))
end
end

function add!(z::FpFieldElem, x::FpFieldElem, y::FpFieldElem)
Expand Down
7 changes: 7 additions & 0 deletions test/flint/gfp_fmpz-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,10 @@ end
R = Native.GF(ZZ(19))
@test R([5]) == R(5)
end

@testset "gfp_fmpz.bug" begin
R = Native.GF(ZZRingElem(123456789012345678949))
z = R(1)
mul!(z, z, ZZ(10))
@test z == 10
end

0 comments on commit 2cedd31

Please sign in to comment.