- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SUBROUTINE STRCPY(STR1,STR2,N)
C
C @(#)strcpy.F 3.2 11/21/89
C
C Purpose:
C COPIES UP TO N CHAR OF STR2 TO STR1
C
C Argument List Definitions:
C STR1 - String to copy into
C STR2 - String to copy from
C N - Max char to copy
C
C---------END OF DESCRIPTION -------
C
USE CSTR_MOD
CHARACTER*(*) STR1,STR2
CHARACTER(len=:), allocatable :: dest
include 'cdefsu.inc'
I = MIN(N,LEN(STR2))
IF(use_cstr) THEN
allocate(character(len=I) :: dest)
call cstrcpy(dest, STR2, I)
STR1 = dest
RETURN
END IF
C
STR1 = ' '
STR1(1:I) = STR2(1:I)
RETURN
END
So what happens with this subroutine local variable being allocated every call, but never deallocated? It doesn't crash with a message saying it was already allocated on the subsequent calls. It seems to work fine most of the time. But I have a case where I get a crash, but if I add a deallocate it doesn't crash. So I suspect memory corruption, but I'm not sure how the compiler handles this situation because it is just a subroutine local variable.
Thanks,
Dave
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Local variables with the ALLOCATABLE attribute but not SAVE get automatically deallocated when the procedure returns.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve, any thoughts on why adding a deallocate statement causes my code to not crash?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I can answer my own question. I think the automatic deallocation checks the heap which was corrupted by code in another routine, but not checked there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Glad to hear you got it sorted out.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page