[Bug fortran/69668] New: Error reading namelist opened with DELIM='NONE'

2016-02-04 Thread phil1691 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69668

Bug ID: 69668
   Summary: Error reading namelist opened with DELIM='NONE'
   Product: gcc
   Version: 5.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: fortran
  Assignee: unassigned at gcc dot gnu.org
  Reporter: phil1691 at gmail dot com
  Target Milestone: ---

When reading a namelist opened with DELIM='NONE' and filling an array, the
content of the file is not read correctly.

Example:
program namelist
  implicit none

  integer,parameter :: tabsz=10
  integer :: i,ilu
  character(len=10),dimension(tabsz) :: tab
  namelist/tab_nml/tab

  tab(:)='invalid'

  open(unit=ilu,file="data.nml",delim='NONE')
  READ(UNIT=ilu,NML=tab_nml)
  close(unit=ilu)

  do i=1,tabsz
print *,'i=',i,' tab(i)=***',tab(i),'***'
  end do

end program namelist

with the following namelist (data.nml file):
&tab_nml
  tab(1)='in1',
  tab(2)='in2'
/

The output is:
> ./a.out 
 i=   1  tab(i)=***in1   ***
 i=   2  tab(i)=***tab(2)='in***
 i=   3  tab(i)=***2'***
 i=   4  tab(i)=***invalid   ***
 i=   5  tab(i)=***invalid   ***
 i=   6  tab(i)=***invalid   ***
 i=   7  tab(i)=***invalid   ***
 i=   8  tab(i)=***invalid   ***
 i=   9  tab(i)=***invalid   ***
 i=  10  tab(i)=***invalid   ***

This problem appears with GCC 5.3.0 and also 5.2.0.

If DELIM is set to 'APOSTROPHE' or 'QUOTE', the code works as expected.
The fortran standards (95, 2003, 2008) say about the DELIM option: "This mode
has no effect on input".

[Bug fortran/99711] New: Crash when reading an allocated character array in namelist

2021-03-22 Thread phil1691 at gmail dot com via 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)