[committed] Fix PR libgfortran/79540

Message ID 77487ad6-1434-28aa-ad4f-dd25e44ac86f@bell.net
State New
Headers show
Series
  • [committed] Fix PR libgfortran/79540
Related show

Commit Message

John David Anglin March 25, 2019, 11:59 a.m.
With the following fortran format from the gfortran.dg/fmt_fw_d.f90 test

print '(f2.1)',    100.000000
end

The computed number of digits is negative.  On hppa-hpux, this causes a stack overflow
in memcpy.  The attached change skips the copy when ndigits is not positive.  We also only
fill put with nulls when i in non negative.  This fixes the testcase with no regressions.

Committed to trunk.

Dave
-- 
John David Anglin  dave.anglin@bell.net

Patch

Index: io/write_float.def
===================================================================
--- io/write_float.def	(revision 269890)
+++ io/write_float.def	(working copy)
@@ -620,7 +620,7 @@ 
     }

   /* Set digits after the decimal point, padding with zeros.  */
-  if (nafter > 0)
+  if (ndigits >= 0 && nafter > 0)
     {
       if (nafter > ndigits)
 	i = ndigits;
@@ -627,7 +627,8 @@ 
       else
 	i = nafter;

-      memcpy (put, digits, i);
+      if (i > 0)
+	memcpy (put, digits, i);
       while (i < nafter)
 	put[i++] = '0';