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.

Reply via email to