[Bug fortran/51869] New: Realloc on assignment wrongly assumes that MALLOC returnes '\0'-set memory

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jan 16 15:31:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51869

             Bug #: 51869
           Summary: Realloc on assignment wrongly assumes that MALLOC
                    returnes '\0'-set memory
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


The following program fails at run time with an abort signal. It works with an
explicit ALLOCATE.

The reason is that the code assumes that MALLOC will return '\0' set memory:

        if (july4 != 0B) goto L.100;
        july4 = (struct show *) __builtin_malloc (144);
        L.100:;
        D.3174 = *july4;
        *july4 = new_show (&fireworks, &air);
        if (D.3174.rocket.position.data != 0B)
          __builtin_free ((void *) D.3174.rocket.position.data);


module soop_stars_class
  implicit none
  type soop_stars
    real ,dimension(:,:) ,allocatable :: position
  end type
  type show
    type(soop_stars) :: rocket
  end type
contains
  function new_show(boom)
    type(soop_stars) ,intent(in) :: boom
    type(show) :: new_show
    new_show%rocket = boom
  end function
end module

program main
  use soop_stars_class
  implicit none

  type(soop_stars) :: fireworks
  type(show) ,allocatable :: july4

  allocatE(fireworks%position(2,2))
!  allocate(july4)
  fireworks%position = 33.0

  july4 = new_show(boom=fireworks)
end program



More information about the Gcc-bugs mailing list