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

            Bug ID: 90421
           Summary: Invalid memory write in allocate on assignment to a
                    class(*) variable
           Product: gcc
           Version: 9.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mscfd at gmx dot net
  Target Milestone: ---

The following code (classstar_alloc3 from PR86328, but much reduced; the
original bug case from this PR has been fixed, the one below was intended as a
work around) shows an invalid write of size 2 with valgrind. Compiling with

gfortran-9 -fsanitize=address -g classstar_alloc3.f90 -o classstar_alloc3

and executing classstar_alloc3 gives

==27530==ERROR: AddressSanitizer: heap-buffer-overflow on address
0x6020000000b1 at pc 0x7f43577d3e9e bp 0x7fff7c4b5ce0 sp 0x7fff7c4b5490
WRITE of size 2 at 0x6020000000b1 thread T0
    #0 0x7f43577d3e9d in __interceptor_memmove
(/usr/lib64/libasan.so.5+0x39e9d)
    #1 0x400ddc in __copy_character_1 /home/xxx/classstar_alloc3.f90:1
    #2 0x4022d3 in rrr /home/xxx/classstar_alloc3.f90:28
    #3 0x401dc0 in classstar_alloc3 /home/xxx/classstar_alloc3.f90:19
    #4 0x402625 in main /home/xxx/classstar_alloc3.f90:19
    #5 0x7f4356803f89 in __libc_start_main (/lib64/libc.so.6+0x20f89)
    #6 0x400c99 in _start (/home/xxx/classstar_alloc3+0x400c99)

0x6020000000b1 is located 0 bytes to the right of 1-byte region
[0x6020000000b0,0x6020000000b1)
allocated by thread T0 here:
    #0 0x7f4357885600 in malloc (/usr/lib64/libasan.so.5+0xeb600)
    #1 0x4020ba in rrr /home/xxx/classstar_alloc3.f90:28
    #2 0x401dc0 in classstar_alloc3 /home/xxx/classstar_alloc3.f90:19
    #3 0x402625 in main /home/xxx/classstar_alloc3.f90:19
    #4 0x7f4356803f89 in __libc_start_main (/lib64/libc.so.6+0x20f89)
...


program classstar_alloc
   class(*), allocatable :: a, b

   allocate(a, source='01')
   b = a
end program classstar_alloc

Reply via email to