This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libfortran/36857] New: Non-English locale breaks gfortran float formatting ("printf is broken")
- From: "pav at iki dot fi" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Jul 2008 19:47:21 -0000
- Subject: [Bug libfortran/36857] New: Non-English locale breaks gfortran float formatting ("printf is broken")
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
GFortran float printing breaks when a non-English locale is selected. Instead,
"Internal error: printf is broken" appears. The failing part is a sanity check
in libgfortran, where it was forgotten that in some non-English locales,
sprintf will format floats using a comma instead of a period as the decimal
separator.
Tested gcc version 4:4.2.3-1ubuntu6 as bundled on Ubuntu Hardy, but probably
present also in trunk.
The following code triggers this bug:
bug.f90:
--------
program main
CALL badlocale()
WRITE(*,'(G2.4)') 1.2345
end program main
bug.c:
------
#include <locale.h>
void badlocale_() { setlocale(LC_ALL, "fi_FI.UTF-8"); }
The compiled program to fails with internal error:
gcc -c -o bug.o bug.c; gfortran -o bug bug.f90 bug.o -lc ; ./bug
At line 3 of file bug.f90
Internal Error: printf is broken
If the code executed correctly, the expected output would be
1,235
To my understanding the failing code appears to be in
libgfortran/io/write_float.def:output_float (around line 126):
/* Check the given string has punctuation in the correct places. */
if (d != 0 && (buffer[2] != '.' || buffer[ndigits + 2] != 'e'))
internal_error (&dtp->common, "printf is broken");
Before execution arrives here, the buffer is filled by sprintf in write_float,
and as said, in some locales the correct formatting of a float will contain a
comma instead of a period.
--
Summary: Non-English locale breaks gfortran float formatting
("printf is broken")
Product: gcc
Version: 4.2.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libfortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: pav at iki dot fi
GCC build triplet: i486-linux-gnu
GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36857