mpz_set_str fails if minus sign is followed by white space

Trevor Spiteri tspiteri at ieee.org
Sat Feb 10 21:07:42 UTC 2018


mpz_set_str and mpz_init_set_str fail when white space immediately
follows the minus sign, for example with the string "- 1". Other strings
like " -1 1 " are parsed correctly.

This code:

#include <gmp.h>
#include <stdio.h>
int main()
{
    mpz_t z;
    int ret = mpz_init_set_str(z, "- 1", 10);
    printf("%d\n", ret);
    return 0;
}

outputs:

-1



More information about the gmp-bugs mailing list