`mpz_set_d' causes segmentation faults on parameters less than 2^-32.

Torbjorn Granlund tege at swox.com
Wed May 31 17:09:24 CEST 2006


KAMADA Makoto <m_kamada at nifty.com> writes:

  `mpz_set_d' causes segmentation faults on parameters less than 2^-32.
  I'm not sure that this problem is restricted to my PC.
  It might be a compiler's problem.
  
Thanks for your clear and complete bug report.

The bug is in mpz/set_d.c.  It was introduced back in 2003
as part of a compiler bug workaround.  Unfortunately,
the workaround introduced this bug.

* mpz/set_d.c: Don't use a special case for d < MP_BASE_AS_DOUBLE, gcc
  3.3 -mpowerpc64 on darwin gets ulonglong->double casts wrong.


This patch should help:

* mpz/set_d.c: Handle negative return values from __gmp_extract_double.

Index: mpz/set_d.c
===================================================================
RCS file: /home/cvsfiles/gmp42/mpz/set_d.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -p -2 -r1.1 -r1.2
*** mpz/set_d.c	14 Mar 2006 15:57:54 -0000	1.1
--- mpz/set_d.c	31 May 2006 14:50:05 -0000	1.2
***************
*** 1,5 ****
  /* mpz_set_d(integer, val) -- Assign INTEGER with a double value VAL.
  
! Copyright 1995, 1996, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
  
  This file is part of the GNU MP Library.
--- 1,6 ----
  /* mpz_set_d(integer, val) -- Assign INTEGER with a double value VAL.
  
! Copyright 1995, 1996, 2000, 2001, 2002, 2003, 2006 Free Software Foundation,
! Inc.
  
  This file is part of the GNU MP Library.
*************** mpz_set_d (mpz_ptr r, double d)
*** 57,60 ****
--- 58,64 ----
      _mpz_realloc (r, rn);
  
+   if (rn <= 0)
+     rn = 0;
+ 
    rp = PTR (r);
  
-- 
Torbjörn


More information about the gmp-bugs mailing list