GMP crashes when using gmp_scanf to scan an mpf_t.

Piotr Olszewski piotr.olszewski at mail.com
Thu Aug 24 18:02:01 UTC 2017


>Sent: Thursday, August 24, 2017 at 5:32 PM
>From: "Marc Glisse" <marc.glisse at inria.fr>
>To: "Piotr Olszewski" <piotr.olszewski at mail.com>
>Cc: gmp-bugs at gmplib.org
>Subject: Re: GMP crashes when using gmp_scanf to scan an mpf_t.
>On Thu, 24 Aug 2017, Piotr Olszewski wrote:
>
>> The crash happened when I tried to run a piece of code from the manual (11.1):
>>
>> /* to read say "topleft (1.55,-2.66)" */
>> mpf_t x, y;
>> char buf[32];
>> gmp_scanf ("%31s (%Ff,%Ff)", buf, x, y);
>>
>> I placed it in a main function and added a line to print the scanned information like this:
>>
>> #include <gmp.h>
>> int main(void)
>> {
>> /* to read say "topleft (1.55,-2.66)" */
>> mpf_t x, y;
>> char buf[32];
>> gmp_scanf ("%31s (%Ff,%Ff)", buf, x, y);
>> gmp_printf("%s (%Ff,%Ff)\n", buf, x, y);
>> return 0;
>> }
>
>This is not a snippet meant to be copy-pasted, the declarations are there
>to show the types of the arguments, but you need to mpf_init the variables
>as usual.
>
>--
>Marc Glisse

Thank you, I read that part of the manual a bit out of context so I assumed that no initialization was necessary. The program runs correctly now that I call mpf_init on both variables before passing them to gmp_scanf.

Regards,
Piotr Olszewski.


More information about the gmp-bugs mailing list