diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 219b1ffd89a..5ead90f9e4c 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,12 @@ +2019-04-16 John David Anglin + + Backport from mainline + 2019-03-25 John David Anglin + + PR libgfortran/79540 + * io/write_float.def (build_float_string): Don't copy digits when + ndigits is negative. + 2019-02-03 Uroš Bizjak PR libfortran/88678 diff --git a/libgfortran/io/write_float.def b/libgfortran/io/write_float.def index b4971fd335e..e303f7d73a8 100644 --- a/libgfortran/io/write_float.def +++ b/libgfortran/io/write_float.def @@ -620,14 +620,15 @@ build_float_string (st_parameter_dt *dtp, const fnode *f, char *buffer, } /* Set digits after the decimal point, padding with zeros. */ - if (nafter > 0) + if (ndigits >= 0 && nafter > 0) { if (nafter > ndigits) i = ndigits; else i = nafter; - memcpy (put, digits, i); + if (i > 0) + memcpy (put, digits, i); while (i < nafter) put[i++] = '0';