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

            Bug ID: 62768
           Summary: Handling of file names with embedded nulls
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jb at gcc dot gnu.org

libgfortran uses various C/POSIX functions for interfacing with the file
systems. In the C/POSIX world, file names are terminated by a null byte,
whereas Fortran strings are not. Consider

program nullfile
  implicit none
  character(len=100) :: s = "hello" // achar(0) // "world", &
       r
  open(10, file=s)
  inquire(unit=10, name=r)
  print *, r
end program nullfile

This program will create a file named "hello", but the inquire will report that
the name is "hello\0world" as that was the Fortran string that was originally
fed to the open statement.

Storing the null-terminated C name in gfc_unit instead of the Fortran string
would fix this, and also save a bunch of malloc/free calls lower in the IO
stack.

Reply via email to