Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

'Implementation defined' behavior in Integer code #192

Open
cyrilbouvier opened this issue Dec 7, 2021 · 0 comments
Open

'Implementation defined' behavior in Integer code #192

cyrilbouvier opened this issue Dec 7, 2021 · 0 comments
Labels

Comments

@cyrilbouvier
Copy link
Member

According to the norm, casting a int64_t to a int32_t (or any signed integral type to a smaller signed integral type) is 'implementation defined' until C++20 (ref: cppreference.com).

Some code of the class Integer (src/kernel/gmp++) can leads to such casts.

For example, in the method to cast an Integer into a int32_t on 64-bit machine (or any machine with sizeof(long int) = sizeof (int64_t)):

Integer::operator int32_t() const
{
return int32_t (mpz_get_si ( (mpz_srcptr)&gmp_rep));
}

In this case the output of mpz_get_si is a signed integral type of 64 bits and is casted into a signed integral type of 32 bits.

I think a more comprehensive proof-reading of the code in gmp++ is necessary to catch other similar problems.

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

No branches or pull requests

2 participants