Skip to content

Commit

Permalink
Fix crash in fmpz_poly_sub_fmpz
Browse files Browse the repository at this point in the history
If `poly` is a zero polynomial and `c` the value zero then
the `fmpz_neg` can crash (it definitely does in Nemo).

Discovered via extended ring conformance tests in Nemo.
  • Loading branch information
fingolfin committed Oct 27, 2024
1 parent 8ed328a commit f46c67c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/fmpz_poly/sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void fmpz_poly_si_sub(fmpz_poly_t res, slong c, const fmpz_poly_t poly)

if (c < 0)
fmpz_sub_ui(res->coeffs + 0, res->coeffs + 0, -c);
else
else
fmpz_add_ui(res->coeffs + 0, res->coeffs + 0, c);

_fmpz_poly_normalise(res);
Expand All @@ -87,7 +87,7 @@ void fmpz_poly_sub_fmpz(fmpz_poly_t res, const fmpz_poly_t poly, fmpz_t c)
if (poly->length == 0)
{
fmpz_poly_set_fmpz(res, c);
fmpz_neg(res->coeffs + 0, res->coeffs + 0);
fmpz_poly_neg(res, res);
}
else
{
Expand Down

0 comments on commit f46c67c

Please sign in to comment.