diff --git a/src/flint/fmpz_poly.jl b/src/flint/fmpz_poly.jl index 8dd3700db..47ea58480 100644 --- a/src/flint/fmpz_poly.jl +++ b/src/flint/fmpz_poly.jl @@ -875,7 +875,13 @@ function sub!(z::ZZPolyRingElemOrPtr, x::ZZPolyRingElemOrPtr, y::ZZPolyRingElemO end function sub!(z::ZZPolyRingElemOrPtr, x::ZZPolyRingElemOrPtr, y::ZZRingElemOrPtr) - @ccall libflint.fmpz_poly_sub_fmpz(z::Ref{ZZPolyRingElem}, x::Ref{ZZPolyRingElem}, y::Ref{ZZRingElem})::Nothing + if is_zero(y) + # HACK HACK HACK: workaround a crash in fmpz_poly_sub_fmpz when subtracting + # 0 from a zero polynomial; see https://github.com/flintlib/flint/pull/2102 + set!(z, x) + else + @ccall libflint.fmpz_poly_sub_fmpz(z::Ref{ZZPolyRingElem}, x::Ref{ZZPolyRingElem}, y::Ref{ZZRingElem})::Nothing + end return z end diff --git a/test/flint/fmpz_poly-test.jl b/test/flint/fmpz_poly-test.jl index 8c6b32fdc..2c61d6afe 100644 --- a/test/flint/fmpz_poly-test.jl +++ b/test/flint/fmpz_poly-test.jl @@ -152,6 +152,9 @@ end @test 12 - g == -x^3-3*x+10 @test ZZRingElem(12) - g == -x^3-3*x+10 + + # verify bugfix (used to crash) + @test is_zero(zero(R) - ZZ(0)) end @testset "ZZPolyRingElem.comparison" begin