]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libfortran/77393 (Revision r237735 changed the behavior of F0.0)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Tue, 6 Sep 2016 23:22:26 +0000 (23:22 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Tue, 6 Sep 2016 23:22:26 +0000 (23:22 +0000)
2016-09-06  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR libgfortran/77393
* io/write_float.def (build_float_string): Recognize when the
result will not fit in the user provided, star fill, and exit
early.

* gfortran.dg/fmt_f0_2.f90: Update test.
* gfortran.dg/fmt_f0_3.f90: New test.

From-SVN: r240018

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/fmt_f0_2.f90
gcc/testsuite/gfortran.dg/fmt_f0_3.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/io/write_float.def

index ff8bc007d960e7995b081f7460cfba7b1b4baf7a..b5157f6b0cabe920b342b921cd1201eb300764f5 100644 (file)
@@ -1,3 +1,9 @@
+2016-09-16  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/77393
+       * gfortran.dg/fmt_f0_2.f90: Update test.
+       * gfortran.dg/fmt_f0_3.f90: New test.
+
 2016-09-07  Dominique d'Humieres  <dominiq@lps.ens.fr>
 
        PR debug/77389
index 01788fab76eb7e65b27957a6f2b18d935030c319..4afba91389e3c5dd36d6f08cecfebb4c203efdd9 100644 (file)
@@ -11,16 +11,12 @@ program testbigf0 ! Can enormous numbers be printed with F0.0 format?
     select case (i)
     case (1)
       write(str, "(f0.0)") -huge(real(1.0,kind=j(1)))
-      if (len(trim(str)).lt.41) error stop "FAILED AT LINE 15"
     case (2)
       write(str, "(f0.0)") -huge(real(1.0,kind=j(2)))
-      if (len(trim(str)).lt.311) error stop "FAILED AT LINE 19"
     case (3)
       write(str, "(f0.0)") -huge(real(1.0,kind=j(3)))
-      if (len(trim(str)).lt.4935) error stop "FAILED AT LINE 23"
     case (4)
       write(str, "(f0.10)") -huge(real(1.0,kind=j(4)))
-      if (len(trim(str)).lt.4945) error stop "FAILED AT LINE 27"
     end select
   enddo
 end program testbigf0
diff --git a/gcc/testsuite/gfortran.dg/fmt_f0_3.f90 b/gcc/testsuite/gfortran.dg/fmt_f0_3.f90
new file mode 100644 (file)
index 0000000..905fe73
--- /dev/null
@@ -0,0 +1,23 @@
+! { dg-do run }
+! PR77393, this segfaulted before
+program testbigf0
+  use ISO_FORTRAN_ENV
+  implicit none
+  integer i
+  integer, parameter :: j(size(real_kinds)+4)=[REAL_KINDS, [4, 4, 4, 4]]
+  character(10000) :: str
+
+  do i=1,size(real_kinds)
+    select case (i)
+    case (1)
+      write(str, "(f8.0)") huge(real(1.0,kind=j(1)))
+    case (2)
+      write(str, "(f18.0)") huge(real(1.0,kind=j(2)))
+    case (3)
+      write(str, "(f20.0)") huge(real(1.0,kind=j(3)))
+    case (4)
+      write(str, "(f40.0)") huge(real(1.0,kind=j(4)))
+    end select
+  enddo
+end program testbigf0
+  
index 256805a3db6a410db85002b71c81a614af170a2a..f9ed4b013a4eb89132d4a1987b594dc54dda0b0c 100644 (file)
@@ -1,3 +1,10 @@
+2016-09-16  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/77393
+       * io/write_float.def (build_float_string): Recognize when the
+       result will not fit in the user provided, star fill, and exit
+       early.
+
 2016-08-31  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/77393
index 04223c043a345f67e49d6b31fc5d39c41d689a6e..504482fa170d3a35709c89fd3a203f1b5d206130 100644 (file)
@@ -174,6 +174,13 @@ build_float_string (st_parameter_dt *dtp, const fnode *f, char *buffer,
     {
     case FMT_F:
       nbefore = ndigits - precision;
+      if ((w > 0) && (nbefore > (int) size))
+        {
+         *len = w;
+         star_fill (result, w);
+         result[w] = '\0';
+         return;
+       }
       /* Make sure the decimal point is a '.'; depending on the
         locale, this might not be the case otherwise.  */
       digits[nbefore] = '.';