[Bug libfortran/56737] [4.6/4.7/4.8/4.9 Regression] Wrong I/O result with format cache for Hollerith strings
jvdelisle at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Mar 28 02:34:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56737
--- Comment #3 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2013-03-28 02:34:32 UTC ---
Note the comment at line 728 of format.c where we must disable format caching
when we encounter FMT_STRING. The problem is related to saving a pointer to a
string rather than the string itself. That pointer can go out of scope on
subsequent I/O operations so caching the format data will not work.
A similar thing happens with FMT_H. Try this not regression tested yet
Index: format.c
===================================================================
--- format.c (revision 196516)
+++ format.c (working copy)
@@ -807,6 +807,7 @@
goto data_desc;
case FMT_H:
+ saveit = false;
get_fnode (fmt, &head, &tail, FMT_STRING);
if (fmt->format_string_len < 1)
{
@@ -984,6 +985,7 @@
break;
case FMT_H:
+ saveit = false;
if (repeat > fmt->format_string_len)
{
fmt->error = bad_hollerith;
I get:
$ gfortran -g -o gfort_bug gfort_bug-2.f90 && valgrind ./gfort_bug
==22746== Memcheck, a memory error detector
==22746== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==22746== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==22746== Command: ./gfort_bug
==22746==
fmt = ( 3(1H ),6h===== ,a 12,i4,6h =====)
title1= end of level
level = 1
===== end of level 1 =====
fmt = ( 3(1H ),6h===== ,a 12,i4,6h =====)
title1= end of level
level = 1
===== end of level 1 =====
==22746==
==22746== HEAP SUMMARY:
==22746== in use at exit: 0 bytes in 0 blocks
==22746== total heap usage: 29 allocs, 29 frees, 27,978 bytes allocated
==22746==
==22746== All heap blocks were freed -- no leaks are possible
==22746==
==22746== For counts of detected and suppressed errors, rerun with: -v
==22746== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
I see no burning need to cache these kinds of formats so just disable it.
More information about the Gcc-bugs
mailing list