| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-options "-std=gnu -fcheck=no-bounds" } |
| 3 |
! |
| 4 |
! PR fortran/113793 |
| 5 |
! |
| 6 |
! Test extension for ALLOCATE with SOURCE= or MOLD= that strings |
| 7 |
! are truncated or padded and no memory corruption occurs |
| 8 |
|
| 9 |
program p |
| 10 |
implicit none |
| 11 |
call test_pad (8, "12345") |
| 12 |
call test_trunc (6, "123456789") |
| 13 |
contains |
| 14 |
subroutine test_pad (n, s) |
| 15 |
integer, intent(in) :: n |
| 16 |
character(*), intent(in) :: s |
| 17 |
character(len=n), allocatable :: a(:), b(:,:) |
| 18 |
if (len (s) >= n) stop 111 |
| 19 |
ALLOCATE (a(100),source=s) |
| 20 |
ALLOCATE (b(5,6),source=s) |
| 21 |
! print *, ">", a(42), "<" |
| 22 |
! print *, ">", b(3,4), "<" |
| 23 |
if (a(42) /= s) stop 1 |
| 24 |
if (b(3,4) /= s) stop 2 |
| 25 |
end |
| 26 |
subroutine test_trunc (n, s) |
| 27 |
integer, intent(in) :: n |
| 28 |
character(*), intent(in) :: s |
| 29 |
character(len=n), allocatable :: a(:), b(:,:) |
| 30 |
if (len (s) <= n) stop 222 |
| 31 |
ALLOCATE (a(100),source=s) |
| 32 |
ALLOCATE (b(5,6),source=s) |
| 33 |
! print *, ">", a(42), "<" |
| 34 |
! print *, ">", b(3,4), "<" |
| 35 |
if (a(42) /= s(1:n)) stop 3 |
| 36 |
if (b(3,4) /= s(1:n)) stop 4 |
| 37 |
end |
| 38 |
end |