Created
December 12, 2013 22:09
-
-
Save dstuebe/7936460 to your computer and use it in GitHub Desktop.
Test case for weird heap corruption / free error.
Depending on the index which overruns the bounds the program fails on deallocate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!**************************************************************************** | |
! | |
! PROGRAM: hello | |
! | |
! PURPOSE: Test program for strange Heap Corruption error in windows | |
! | |
!**************************************************************************** | |
program hello | |
implicit none | |
integer :: ierr, i,j | |
real, allocatable :: bar(:,:) | |
! Body of hello | |
print *, 'Hello World' | |
print *, 'Allocated? ', allocated(bar) | |
allocate(bar(3,3), stat=ierr) | |
print *, 'bar Allocation result:', ierr, allocated(bar) | |
do j=1,4 | |
do i=1,3 | |
bar(i,j) = 33.3 ! Causes Heap Corruption on Deallocate! | |
!bar(j,i) = 33.3 ! No Error or Exception in Default Release Build | |
end do | |
end do | |
print *, 'Set values - Yikes!' | |
! Nicely formatted output... | |
!do j = 1,4 | |
! WRITE(*,220) j,(bar(i,j),i=1,3) | |
!end do | |
!220 format(i5,2x,<3>f8.1) | |
print *, 'Allocated? ', allocated(bar) | |
deallocate(bar, stat=ierr) | |
print *, 'Goodbye World', ierr, allocated(bar) | |
end program hello |
brianmckenna
commented
Dec 12, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment