[Bug libfortran/20074] New: reshape of pointer array segfaults at runtime

Thomas dot Koenig at online dot de gcc-bugzilla@gcc.gnu.org
Sat Feb 19 18:27:00 GMT 2005


>From a posting to comp.lang.fortran.

$ cat tryresh.f90
! From: "Alfredo Buttari" <pitagoras@tin.it>
! Newsgroups: comp.lang.fortran
! Subject: reshape problem
! Date: 18 Feb 2005 09:54:35 -0800

program tryreshape

  integer,allocatable :: vect1(:),resh1(:,:)
  integer,pointer :: vect(:),resh(:,:)
  integer :: vect2(2*4), resh2(2,4)
  integer :: r, s(2)

  r=2;  nb=4

  s(:)=(/r,nb/)

  allocate(vect(nb*r),vect1(nb*r))
  allocate(resh(r,nb),resh1(r,nb))

  vect =1
  vect1=1
  vect2=1

  write(*,'("Reshaping to  ",1(i1.1,"x"),i2.2)')s

! THIS WORKS
  resh2 = reshape(vect2,s)
  write(*,'("resh2: ",1(i3,2x))')resh2(1,1)

! THIS WORKS
  resh1 = reshape(vect1,s)
  write(*,'("resh1: ",1(i3,2x))')resh1(1,1)

! THIS DOESN'T
  resh = reshape(vect,s)
  write(*,'("resh : ",1(i3,2x))')resh(1,1)

end program tryreshape
$ gfortran -g tryresh.f90
$ ./a.out
Reshaping to  2x04
resh2:   1
resh1:   1
Segmentation fault
$ gdb ./a.out
GNU gdb 6.3-debian
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-linux"...Using host libthread_db library
"/lib/tls/libthread_db.so.1".

(gdb) r
Starting program: /home/ig25/Krempel/a.out
Reshaping to  2x04
resh2:   1
resh1:   1

Program received signal SIGSEGV, Segmentation fault.
0x40127cef in memcpy () from /lib/tls/libc.so.6
(gdb) bt
#0  0x40127cef in memcpy () from /lib/tls/libc.so.6
#1  0x40056f08 in *_gfortrani_reshape_packed (ret=0x0, rsize=32,
    source=0x20 <Address 0x20 out of bounds>, ssize=32, pad=0x0, psize=4)
    at ../../../gcc/libgfortran/intrinsics/reshape_packed.c:45
#2  0x40044b8b in *_gfortran_reshape_4 (ret=0xbffff4c4, source=Variable "source"
is not available.
)
    at ../../../gcc/libgfortran/generated/reshape_i4.c:160
#3  0x08048d6f in MAIN__ () at tryresh.f90:35
#4  0x08048f43 in main (argc=32, argv=0x20)
    at ../../../gcc/libgfortran/fmain.c:18
(gdb) q
The program is running.  Exit anyway? (y or n) y
$ gfortran -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/ig25 --enable-languages=c,f95
Thread model: posix
gcc version 4.0.0 20050219 (experimental)

-- 
           Summary: reshape of pointer array segfaults at runtime
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Thomas dot Koenig at online dot de
                CC: gcc-bugs at gcc dot gnu dot org


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



More information about the Gcc-bugs mailing list