This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch, libgfortran] PR32446 F0.n output format fails with large numbers
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 22 Jun 2007 20:03:11 -0700
- Subject: [patch, libgfortran] PR32446 F0.n output format fails with large numbers
:ADDPATCH fortran:
This patch fixes this by setting the ndigits to zero appropriately. If you
study the code you will see that previously, ndigits was going negative for the
case where the nbefore is greater. The initial patch I posted to the PR was way
wrong. :)
Regression tested on x86-64-pc-Gnu/Linux.
Test case included.
OK for trunk?
Eventually, this should go to 4.2. It is a regression against g77. I was able
to reproduce the failure with large width formats and large real constants and
they passed on g77.
Regards,
Jerry
2007-06-22 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/32446
* io/write.c (output_float): Calculate ndigits correctly for large
numbered formats that must pad zeros before the decimal point.
! { dg-do run }
! PR32446 printing big numbers in F0.1 format.
! This segfaulted before the patch.
open (10, status="scratch")
write (10,'(F0.1)') huge(1.0)
END
Index: write.c
===================================================================
*** write.c (revision 125870)
--- write.c (working copy)
*************** output_float (st_parameter_dt *dtp, cons
*** 810,825 ****
if (nbefore > 0)
{
if (nbefore > ndigits)
! i = ndigits;
else
! i = nbefore;
!
! memcpy (out, digits, i);
! while (i < nbefore)
! out[i++] = '0';
digits += i;
- ndigits -= i;
out += nbefore;
}
/* Output the decimal point. */
--- 810,830 ----
if (nbefore > 0)
{
if (nbefore > ndigits)
! {
! i = ndigits;
! memcpy (out, digits, i);
! ndigits = 0;
! while (i < nbefore)
! out[i++] = '0';
! }
else
! {
! i = nbefore;
! memcpy (out, digits, i);
! ndigits -= i;
! }
digits += i;
out += nbefore;
}
/* Output the decimal point. */