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

            Bug ID: 78758
           Summary: [7 Regression] Warning: '__builtin_memcpy' ...
                    overflows the destination for string assignment
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gmx dot de
  Target Milestone: ---

I just saw the following warning:

% gfc-trunk -c gfcbug137.f90 -O
gfcbug137.f90:7:0:

      longname(5:) = " " // adjustl (name(5:))

Warning: '__builtin_memcpy' writing 12 bytes into a region of size 11 overflows
the destination [-Wstringop-overflow=]

for the simple code:

% cat gfcbug137.f90
integer function get_satid (name)
  character(len=*), intent(in) :: name
  character(len=16)            :: longname

  longname = name
  if (name(1:4) == "GOES" .and. name(5:5) /= " ") then
     longname(5:) = " " // adjustl (name(5:))
  end if
  get_satid = satid_longname (longname)
end function get_satid

% gfc-trunk --version | head -1
GNU Fortran (GCC) 7.0.0 20161208 (experimental)

Note: optimization (-O or higher) is essential; there is no warning
with -O0 or -Og.

For Fortran code, the expected behavior in string assignment is that there
should be no overflow.

Reply via email to