Skip to content

'Implementation defined' behavior in Integer code #192

@cyrilbouvier

Description

@cyrilbouvier

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions