This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libfortran/17195] New: Infinite loop in output_float in libgfortran/io/write.c


This program,

   program t
   real(8) y
   print*, 'huge(y) = ', huge(y)
   end program t

when compiled with "gfortran -static -o t t.f90" leads
to a program "t", which executes an infinite loop.  The 
problem is in libgfortran/io/write.c where write_real()
sets the global variable g.scaling=1.  We eventually end
up executing this code in output_float() where
n = huge(y) and sca = 1.

  if (ft == FMT_F || ft == FMT_E || ft == FMT_D)
    {
      if (ft == FMT_F)
        scale_flag = 0;
      if (ft == FMT_D)
        exp_char = 'D' ;
      minv = 0.1;
      maxv = 1.0;

      /* Calculate the new val of the number with consideration
         of global scale value.  */
      while (sca >  0)
        {
          minv *= 10.0;
          maxv *= 10.0;
          n *= 10.0;       /* XXXXX huge(y) * 10 becomes Inf. */
          sca -- ;
          neval --;
        }

      /* Now calculate the new Exp value for this number.  */
      sca = g.scale_factor;
      while(sca >= 1)
        {
          sca /= 10;
          digits ++ ;
        }
    }

Further down, we hit this loop and n = Inf > maxv, forever.

   while (scale_flag && n > 0.0 && n > maxv)
     {
       if (n > maxv)
         {
           n = n / 10.0 ;
           neval ++;
         }
     }

-- 
           Summary: Infinite loop in output_float in libgfortran/io/write.c
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sgk at troutmask dot apl dot washington dot edu
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: amd64-unknown-freebsd5.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17195


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]