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

Mpq::ratio is unsafe #21

Closed
Rufflewind opened this issue Apr 19, 2017 · 1 comment
Closed

Mpq::ratio is unsafe #21

Rufflewind opened this issue Apr 19, 2017 · 1 comment

Comments

@Rufflewind
Copy link

Rufflewind commented Apr 19, 2017

Mpq::ratio is unsafe:

extern crate gmp;
use gmp::mpq::Mpq;
use gmp::mpz::Mpz;
fn main() {
    println!("{:?}", Mpq::ratio(&Mpz::one(), &-Mpz::one()));
    //                                        ^--- (!)
}

results in:

zsh: segmentation fault (core dumped)

Tested this using gmp-6.1.2 on Arch Linux.

To quote the manual:

Note that if an assignment to the numerator and/or denominator could take an mpq_t out of the canonical form described at the start of this chapter (see Rational Number Functions) then mpq_canonicalize must be called before any other mpq functions are applied to that mpq_t.

There are probably other rational functions that need to be scrutinized as well.

@vks
Copy link

vks commented Apr 19, 2017

Mpq::from_str_radix is also affected. #22 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants