public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/99711] New: Crash when reading an allocated character array in namelist
@ 2021-03-22 14:02 phil1691 at gmail dot com
  2021-03-23  1:11 ` [Bug fortran/99711] " jvdelisle at gcc dot gnu.org
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: phil1691 at gmail dot com @ 2021-03-22 14:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99711

            Bug ID: 99711
           Summary: Crash when reading an allocated character array in
                    namelist
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: phil1691 at gmail dot com
  Target Milestone: ---

The following code crashes with a segmentation fault (gcc 10.2.0):
> cat alloc_nml.f90 
program allocnml
  implicit none

  character(len=:), dimension(:), allocatable :: cbulist_ru
  integer :: iluseg

  namelist /nam_bu_ru/ cbulist_ru

  allocate( character(len=10) :: cbulist_ru(5) )

  open(newunit=iluseg, file='list.nml', status='old', &
       action='read', form='formatted', access='sequential')

  read(unit=iluseg, nml=nam_bu_ru)

  print *, cbulist_ru

  close(unit=iluseg)
end program allocnml

With the following namelist file:
> cat list.nml
&NAM_BU_RU
 CBULIST_RU(1) = 'PRES'
 CBULIST_RU(2) = 'NEST'
 CBULIST_RU(3) = 'HTURB'
 CBULIST_RU(4) = 'VTURB'
/

Compilation:
> gfortran -g alloc_nml.f90

Execution:
> ./a.out 

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x146bdba3349f in ???
#1  0x146bdbb57d7a in ???
#2  0x146bdc79df4b in nml_read_obj
        at ../../../gcc-10.2.0-srcdir/libgfortran/io/list_read.c:3142
#3  0x146bdc79ee8a in nml_get_obj_data
        at ../../../gcc-10.2.0-srcdir/libgfortran/io/list_read.c:3512
#4  0x146bdc7a78b7 in finalize_transfer
        at ../../../gcc-10.2.0-srcdir/libgfortran/io/transfer.c:4128
#5  0x400d48 in allocnml
        at
/home/waup/F90/bug_gcc/character_allocatable_namelist/alloc_nml.f90:14
#6  0x400e20 in main
        at
/home/waup/F90/bug_gcc/character_allocatable_namelist/alloc_nml.f90:19
Erreur de segmentation (core dumped)

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2023-08-31 17:22 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 14:02 [Bug fortran/99711] New: Crash when reading an allocated character array in namelist phil1691 at gmail dot com
2021-03-23  1:11 ` [Bug fortran/99711] " jvdelisle at gcc dot gnu.org
2021-03-23  2:11 ` kargl at gcc dot gnu.org
2021-03-23  2:29 ` jvdelisle at gcc dot gnu.org
2021-03-23  2:41 ` jvdelisle at gcc dot gnu.org
2021-03-23  6:16 ` sgk at troutmask dot apl.washington.edu
2021-03-23  7:37 ` philippe.wautelet at aero dot obs-mip.fr
2021-03-24  2:41 ` jvdelisle at gcc dot gnu.org
2021-03-24  3:15 ` jvdelisle at gcc dot gnu.org
2021-03-24  5:35 ` sgk at troutmask dot apl.washington.edu
2021-03-24  5:45 ` sgk at troutmask dot apl.washington.edu
2021-03-25  3:32 ` jvdelisle at gcc dot gnu.org
2021-03-26  1:47 ` jvdelisle at gcc dot gnu.org
2021-03-26  2:25 ` jvdelisle at gcc dot gnu.org
2021-03-26  2:38 ` jvdelisle at gcc dot gnu.org
2021-03-26  6:04 ` sgk at troutmask dot apl.washington.edu
2021-03-26 23:38 ` jvdelisle at gcc dot gnu.org
2021-03-27  3:14 ` jvdelisle at gcc dot gnu.org
2023-08-31 12:58 ` philippe.wautelet at aero dot obs-mip.fr
2023-08-31 17:20 ` sgk at troutmask dot apl.washington.edu
2023-08-31 17:22 ` kargl at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).